Freddy Galvis had a pair of RBI singles for the Phillies, who got another solid outing from Aaron Harang (2-1). The veteran hurler allowed three runs on seven hits with two walks and six strikeouts over six innings.
Bryce Harper hit a long home run for Washington, which had won three straight games.
Jordan Zimmermann (1-2) was tagged for four runs -- two earned -- on four hits and four walks in 6 1/3 innings.
Ryan Howard was replaced by pinch-runner Ben Revere after working a walk against Zimmermann to begin the seventh. Revere stole second base and advanced to third on a flyout before scoring the go-ahead run on a fielder's choice. He beat a throw home from Ryan Zimmerman, who fielded a ground ball hit by pinch- hitter Grady Sizemore.
With two runners aboard in the bottom of the seventh, second baseman Chase Utley made a diving stop on a sharply hit grounder by Zimmerman and threw to first for the final out.
Revere led off the ninth with a double and scored on a two-out single by Herrera to make it 5-3.
Jonathan Papelbon retired the Nationals in order in the bottom of the ninth to earn his third save of the season.
Harang gave up singles to the first two batters of the game and Washington produced a run with consecutive groundouts.
The Phillies were able to capitalize on a couple defensive miscues by Nationals shortstop Ian Desmond in the third to grab a 2-1 lead. Desmond bungled an innocuous grounder by Harang but it appeared he recovered in time to narrowly throw the Philadelphia right-hander out at first base.
However, the Phillies challenged the play and it was overturned as Harang beat the throw. Desmond was charged with his eighth error of the young season, and it sparked the Philadelphia offense.
Herrera sent a double the opposite way to left field and Galvis tied it with an RBI single to center.
Philadelphia moved ahead when Desmond couldn't complete a double play on Utley's grounder to second baseman Dan Uggla. Desmond dropped the ball on the exchange, allowing Herrera to score.
The Nationals tied it in the fourth inning on an RBI single by Jose Lobaton, but the Phillies regained the lead with a two-out rally in the next inning.
After retiring the first two batters on only three pitches, Zimmermann walked Herrera, who stole second and came around to score on Galvis' blooper to left.
Harper crushed a home run to deep center field in the bottom of the fifth to even the game at 3.