PHILADELPHIA — Freddy Galvis hit a sacrifice fly in the bottom of the 10th inning to lift the Philadelphia Phillies to a 6-5 comeback win over the Washington Nationals on Sunday.

Pinch-hitter Aaron Altherr connected for a tying, three-run homer in the eighth and the Phillies rallied to avoid a three-game sweep.

Odubel Herrera led off the bottom of the 10th with a checked-swing double down the left-field line off Blake Treinen (0-1). After Altherr was intentionally walked, pitcher Vince Velasquez batted for reliever Hector Neris and reached on a bunt single. Treinen fanned Andres Blanco, but Galvis drove in the winning run with a liner to center.

Jayson Werth had four hits, including two homers, for the Nationals.

Neris (1-1) tossed two scoreless innings for the win.

Cesar Hernandez and Daniel Nava singled off Matt Grace in the eighth. Matt Albers entered and Altherr drove his first pitch out to left-center for his first career pinch-hit homer to tie it at 5. Albers had not allowed a run this season in nine previous appearances spanning 11 1/3 innings.

Werth clocked a solo homer to right-center for 1-0 lead in the first. He gave the Nationals a 3-2 lead in the fifth when he lined a two-run shot to left. Werth tossed his bat aside and slowly jogged around the bases, soaking in the boos he’s been hearing since leaving Philadelphia seven years ago.

Galvis hit a two-run double in the fourth to give the Phillies a brief 2-1 lead. A fielding error by shortstop Trea Turner on a grounder earlier in the inning led to the unearned runs.

The major league-leading Nationals (21-10) had won four in a row, while the Phillies (13-17) had lost eight of nine.

Nationals starter Tanner Roark allowed two unearned runs and two hits in six innings.

Phillies starter Jeremy Hellickson gave up three runs and five hits in 4 2/3 innings. He has failed to pitch five innings in two straight starts.

The Nationals got two runs off reliever Jake Thompson in the seventh. Anthony Rendon had an RBI single, and Adam Lind followed with a sacrifice fly.

Worthy foe

Werth has 15 homers in his last 49 games in Philadelphia. His last three multi-homer games have come in Philly. He signed a seven-year, $126 million deal with the Nationals after helping the Phillies win four division titles, two pennants and the 2008 World Series from 2007-10.

Trainer's room

Nationals: Bryce Harper, the 2015 NL MVP, was out of the lineup for a third straight game after he strained his left groin on Thursday.

Phillies: Altherr wasn’t in the lineup for a second consecutive game due to a sore left wrist that certainly didn’t seem to bother him when he came to the plate.