WASHINGTON — Rougned Odor hit a three-run homer off Hunter Harvey with two outs in the ninth inning, giving the San Diego Padres an 8-6 win over the Washington Nationals on Thursday that stopped a steak of five straight series losses.

“He is a guy that throws really hard,” Odor said. “I was looking for the fastball and he throw me that fastball and I was ready to go.”

Jake Cronenworth and Juan Soto singled leading off the ninth. Harvey (2-2) struck out Xander Bogaerts and Matt Carpenter, and Odor homered on a 1-0 fastball, lining the ball just inside the right-field foul pole.

San Diego had been 0-22 this year when trailing after eight innings.

The Baltimore Banner thanks its sponsors. Become one.

“That ninth inning is something we needed to grab onto and hold,” Cronenworth said. “It’s a feeling we want to feel all the time: the feeling of stringing those quality at-bats together and stringing some runs together, whether it comes from a base hits or a big home run like Odor had today.”

Washington trailed 5-1 before a five-run seventh.

Odor also hit a two-run double and had five RBIs, one short of his career high. He has homered in consecutive games and has 10 hits in his last 12 games as he subs for the injured Manny Machado.

“You feel good when he’s at the plate right now,” manager Bob Melvin said. “I’ve said often he’s not afraid of any situation. I’ve seen him many times over on the other side. Right now he’s swinging a hot bat for us and came up at the right time.”

Soto, the former Nationals star, reached base five times on four walks and a single.

The Baltimore Banner thanks its sponsors. Become one.

Drew Carlton (1-0) pitched a 1-2-3 eighth for his first decision in parts of three major league seasons with Detroit and San Diego. Josh Hader struck out two in a perfect ninth for his 13th save in 15 chances.

San Diego, which took two of three from the Nationals, had not won a series since May 1-3 against Cincinnati.

“We have been needing a couple swings like that,” Melvin said. “Not only did we get to cash in on some runners in scoring position early in the game, we did obviously late as well. Odor has had a lot to do with that lately.”

Down 5-1, the Nationals had seven straight hits against Tim Hill and Nick Martinez while batting around in the seventh. Ruiz’s pinch single caromed off the glove of Odor at second as the go-ahead run scored. Jeimer Candelario had an RBI double and Alex Call laid down a perfect bunt single to tie the game at 5.

Padres catcher Brett Sullivan tagged out Call trying to score on a pitch that got away from the plate.

The Baltimore Banner thanks its sponsors. Become one.

Padres starter Blake Snell rebounded from his worst start this season, allowing one run and four hits over five innings while retiring 10 of 11 batters at one point. He gave up six runs May 19 in a 6-1 loss to Boston.

“I felt really good today so I am frustrated that I hurt myself in a lot of situations I didn’t need to be in,” Snell said. “We will just keep getting better and just learn from it. There’s a lot I know I can clean up.”

Trent Grisham hit a two-run homer in the second off Jake Irvin, his fifth of the season and first since April 13.