Despite chasing for nearly the entirety of the game, the San Diego Padres bottom of the lineup came through in the clutch again to rally past the Arizona Diamondbacks 3-2 on Wednesday night at Chase Field.

After coming up empty with a ton of traffic in the eighth inning, Ryan O’Hearn led off the ninth by crushing a low sweeper 391 feet to right center field off reliever Kyle Backus to tie the game. Then after Xander Bogaerts followed up with a double and Jake Cronenworth bunted him over, Jose Iglesias cracked the go-ahead single to right field.

It was the first home run with the Padres by O’Hearn after going 1-for-12 over his first dozen at bats since being acquired from Baltimore at the trade deadline. It was just the second win all season where San Diego rallied to win after trailing through eight, and won their third straight series.

Bogaerts hit a solo home run for the second consecutive game, but a pair of early runs allowed by Nestor Cortes in his San Diego debut gave the hosts a lead they enjoyed for most of the night. Corbin Carroll hit a first inning solo home run and Alek Thomas hit a second inning, bases-loaded sacrifice fly for the Diamondbacks.

Adrian Morejon allowed one hit in two innings of work to earn his ninth with for San Diego, then Mason Miller notched his first save in the Brown and Gold by striking out three and walking one for his 21st overall save of the year.

The Padres had appeared to load the bases with one out in the eighth when Freddy Fermin dropped a bunt for a leadoff hit, then an error by third baseman Blaze Alexander allowed Ramón Laureano to reach on a fielder’s choice.

Then Backhus replaced Jake Woodford and was able to get Jackson Merrill to ground it on the left side of the infield, where Alexander made up for his error by beating Fermin to the bag with a dive for the forceout that was reviewed and overturned. A strikeout by Manny Machado ended the threat.

Those two opportunities were only the third and fourth at bats with runners in scoring position for the visitors.

Cortes, who drew into the rotation after J.P. Sears was optioned to Triple-A El Paso and Sean Reynolds recalled on Thursday, made his first Majors start since April 3 and just his third of the season.

Aside from the early home run, which came off a four-seam fastball that leaked middle-middle, the major danger came when the Diamondbacks loaded the bases with nobody out after a leadoff infield single by Tyler Locklear and back-to-back hit by pitches that put Alexander and James McCann aboard.

The Thomas sacrifice fly would be all though, as Cortes got Jorge Barrosa to fly out to right field and then Ketel Martel popped out to second. Cortes would allow three baserunners the rest of the way, all on walks, and getting a double-play in the third. He finished with three hits and two runs allowed in 4 â…” innings with three strikeouts and three walks.

In the fifth Cronenworth hit a one out single and Iglesias walked, with Fermin following with a flyout that allowed Cronenworth to take third. San Diego then attempted a double-steal, with Gerardo Perdomo firing back home to catcher McCann and getting the final out of the inning at home plate.

Jason Adam replaced Cortes with two men aboard on consecutive two-out walks in the fifth to strikeout Perdomo on four pitches. He followed up by retiring all three batters in the sixth.

San Diego did not start Fernando Tatis Jr. for just the third time all season, giving him a rare day off for the first time since June 7 in Milwaukee.

After an off-day on Thursday, the Padres will be back in action at home against the Boston Red Sox for their only non-league series over a 20-day stretch. Nick Pivetta (11-3, 2.73 ERA) will get the nod in the opener against Walker Buehler (6-6, 5.74 ERA), with first pitch scheduled for 6:40 p.m. at Petco Park.

This story will be updated.