Werth got three hits, including an RBI single in the fourth and his two-out, tiebreaking shot off reliever Zach Miner.
In his second major league game, Tanner Roark (1-0) pitched two spotless innings. Tyler Clippard surrendered Domonic Brown's 26th home run in the eighth and Rafael Soriano pitched the ninth for his 29th save.
Jake Diekman (0-3) took the loss.
Darin Ruf also homered for the Phillies, who wasted an early 4-0 lead and have dropped 10 straight road games.
Phillies starter Cliff Lee left after six innings with a 4-3 edge.
Pinch-hitter Steve Lombardozzi drew a leadoff walk from Diekman in the seventh. With one out and runners at the corners, Diekman faced Bryce Harper in a lefty vs. lefty matchup.
Harper bunted, and the ball popped in the air and landed in front of second baseman Chase Utley, who recorded a forceout at second as the tying run scored. Werth, a former Phillies star, then greeted Miner with his homer, and Anthony Rendon tacked on a two-run single later in the inning.
The Nationals' rally denied Phillies manager Charlie Manuel the 1,000th win of his career.
Lee had lost his previous three starts. The veteran left-hander has not won since defeating Atlanta on July 5.
Lee picked up an RBI with a safety-squeeze bunt during Philadelphia's four-run second inning. Ruf hit a two-run homer off Taylor Jordan and later Jimmy Rollins singled home a run.
On his 26th birthday, Wilson Ramos' two-out single in the sixth scored Werth, trimming Philadelphia's lead to 4-3. Werth scored three times.