PHILADELPHIA (AP) Freddy Galvis elevated the ball at just the right time.

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.

Phillies manager Pete Mackanin has criticized Galvis for too many uppercut swings. He was looking for a fly ball there, however.

''If you noticed, he swung down on the ball and got some top-spin on it,'' Mackanin said.

Galvis finished with two hits and three RBIs.

''We needed to win a game like this,'' he said.

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.

''That's the first mistake Albers made this year,'' Nationals manager Dusty Baker said. ''He had to hit it a ton because the wind was blowing the other way.''

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.

''My command was shaky,'' Hellickson said.

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.

VINNY THE BAT

Velasquez became the first Phillies pitcher with a pinch hit since Cole Hamels on April 10, 2008, at the New York Mets. Velasquez put down a perfect bunt and beat it without a throw.

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. Baker said Harper will play Monday night.

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.

UP NEXT

Nationals: LHP Gio Gonzalez (3-0, 1.64 ERA) starts the opener of a home-and-home, four-game interleague series at Baltimore on Monday. RHP Kevin Gausman (1-3, 7.55) goes for the Orioles.

Phillies: After an off day, RHP Jerad Eickhoff (0-3, 4.00) pitches the opener of a two-game interleague set vs. Seattle. RHP Hisashi Iwakuma (0-2, 4.35) takes the mound for the Mariners.

---

More AP baseball: https://apnews.com/tag/MLBbaseball

Copyright 2017 by Associated Press. Any commercial use or distribution without the express written consent of Associated Press is strictly prohibited.