Nick Markakis and Yamaico Navarro each drove in two runs and the Orioles had 15 hits, including three from Manny Machado.
Hammel (7-2) improved to 4-0 at Nationals Park, striking out eight without a walk and allowing eight hits. He struck out Tyler Moore to end the sixth inning and strand the potential tying run.
Nationals starter Gio Gonzalez kept Baltimore scoreless until the fourth when the Orioles scored three runs. Navarro's bloop RBI single tied the score at 1 and put runners on first and second with one out. After Hammel bunted, Markakis hit a two-out, two-run single.
The Nationals played without Bryce Harper, who has swelling in his left knee.
After allowing only three earned runs in his previous three starts, Gonzalez (3-3) allowed four runs and eight hits over 5 2-3 innings with four walks and three strikeouts.
Machado hit his AL leading 23rd double, stole a base and scored a run. The 20-year-old has seven games with at least three hits since May 10.
With the Nationals searching for offense throughout the season, manager Davey Johnson vowed last week not to shave until the bats came alive. He kept the promise even though Washington scored six runs Sunday and had won three of four games.
''Gio wouldn't let me,'' Johnson cracked pregame, ''but we're getting close.''
The Nationals scored two or fewer runs for the 25th time in 51 games
Moore's RBI single in the second gave the Nationals a 1-0 lead and Denard Span scored in the sixth on Ryan Zimmerman's single after tripling off Hammel.
Matt Wieters hit a sacrifice fly in the fifth put Baltimore up 4-1.
Harper's injury was aggravated in Sunday's 6-1 win over the Philadelphia Phillies and underwent an MRI. Team medical director Wiemi Douoguih said the outfielder has inflammation of the bursa sac in front of his knee, which he anticipates ''clearing up in a couple of days.'' Harper underwent an MRI, which showed some soft tissue swelling, but no structural damage, Douoguih said.
The Nationals and Orioles play four straight games this week with Wednesday and Thursday's contests held in Baltimore.
Notes: The Nationals placed LHP Ross Detwiler on the 15-day disabled list with a right back muscle strain and recalled LHP Xavier Cedeno from Triple-A Syracuse. Johnson did not immediately pick a replacement to pitch in Tuesday's contest. RHP Kevin Gausman (0-1) will make his second career start for the Orioles. ... Douoguih provided updates on several injured Nationals including catcher Wilson Ramos. Out since May 16 with a left hamstring injury, Ramos will miss another four weeks. ... Danny Espinosa (fractured right wrist) missed his fourth straight game, but could ramp up his baseball activities if no additional swelling takes place after the second baseman took swings on Monday. ... Jayson Werth, out since May 2 with a right hamstring strain, could play in rehab games later this week and return to the Nationals active roster next week. ... Hitting coach Rick Eckstein served as first base coach with Tony Tarasco absent due to the birth of his child. ... RHP Yunesky Maya, designated for assignment by the Nationals on Saturday, cleared waivers and was outrighted to Triple-A Syracuse.