Adam LaRoche and Denard Span reached base four times and rookie Corey Brown hit a pinch-homer for Washington, which benefited from nine walks and a hit batter. The Nats, however, overcame three errors and four wild pitches to win a sloppy, three-hour, 38-minute affair.

Ramos hit a three-run homer in the second inning and drove in a run by drawing a bases-loaded walk in the fifth.

Cody Asche went 3-for-4, and his solo homer in the eighth off Tyler Clippard cut Washington's lead, which was once 7-2, to 8-6.

Washington added a run in the ninth when Phillies reliever B.J. Rosenberg threw a wild pitch while striking out Bryce Harper.

Nationals closer Rafael Soriano blanked Philadelphia in the bottom of the inning to post his 37th save.

Gio Gonzalez (9-6) scuffled through 5 2/3 innings for the victory. He allowed five runs (one earned) and five hits while striking out six and walking three. He threw 118 pitches, 73 for strikes. He also had two the wild pitches. Reliever Ryan Mattheus threw the other two.

Philadelphia starter Ethan Martin (2-4) worked 4 2/3 innings, allowing five runs and four hits. He walked five and struck out two.

The Nationals broke on top courtesy of Ramos' three-run homer in the second, his 10th home run of the year. But the Phillies answered with Asche's two-run single in the fourth.

Martin and reliever Justin DeFratus each walked in a run in the fifth, allowing Washington to extend its lead to 5-2.

NOTES: Span extended his career-high hitting streak to 16 games with a third-inning single. ... Earlier in the day, the Nationals selected the contract of SS Zach Walters from Triple-A Syracuse and recalled OF Corey Brown, LHP Xavier Cedeno, INF/OF Jeff Kobernus and OF Eury Perez. ... Phillies SS Jimmy Rollins did not start. He is hitting .183 in 18 games since Ryne Sandberg took over as interim manager in mid-August. Sandberg nonetheless said he likes the strides Rollins is making at the plate. "I see him working on things in the cage and applying them to the game," Sandberg said. Moreover, Sandberg said, "I've noticed Jimmy being engaged. I've noticed him being into it."