Home cooking has served the teams well in the Padres-Dodgers showdowns this month.

Nestor Cortes took a perfect game into the sixth inning and combined with the bullpen on a two-hitter as the Padres knocked the Dodgers out of first place with a 5-1 victory at Petco Park Saturday.

Ramón Laureano had a two-run single in the fourth and Xander Bogaerts added a two-run double in the eighth for the Friars (74-56), who surged ahead of the Dodgers (73-57) during the archrivals’ final series of the regular season.

They’ve allowed Los Angeles just five hits and two runs in back-to-back wins and have a chance to take all three games at Petco from LA.

“The last two nights, when you get six out of your starter, and then you’re able to take a lead, go to your guys and then add on, that recipe usually tastes the best,” manager Mike Shildt said.

After getting swept at Dodger Stadium last weekend, and dropping the opening game of their current home stand, the Padres have won their last five games.

They’ve also done it for most of this week without Jackson Merrill. The Padres put him on the injured list Saturday for the third time this season, making this move retroactive to Aug. 20. Merrill has been moving with a limp since he rolled his ankle at the plate on Aug. 15, suffering a bone bruise.

The pitching staff, though, stepped up for the second straight day. Cortes (2-2) infamously gave up Freddie Freeman’s walk-off grand slam while pitching for the Yankees in last year’s World Series, but the veteran left-hander thoroughly shut down the Dodgers this time around. In doing so, he matched Yu Darvish’s six innings of one-hit ball Friday.

In his fourth start since joining the Padres at the July 31 trade deadline, Cortes retired the Dodgers’ first 16 batters before Miguel Rojas’ sixth-inning single.

“He got into a rhythm right from the very first batter,” Shildt said.

Adrian Morejon got four outs for his third save.

The Dodgers have lost four of six and are in second place for only the second day since April 27 (the Padres briefly overtook them ahead of last week’s series). Freeland, a rookie, connected off Jeremiah Estrada in the eighth to homer in his second straight game.

Tyler Glasnow (1-2) yielded two runs and three hits with four walks in four innings. Glasnow’s hard luck continued, despite it being his birthday Saturday. He is winless in 12 starts since March despite pitching fairly well.

Nick Pivetta (13-4, 2.81) takes the mound in the series finale Sunday against Yoshinobu Yamamoto (10-8, 2.90 ERA).