The Dodgers’ Andy Pages, left, looks on from the dugout...

SAN DIEGO — Nestor Cortes had one of the lowest moments of his baseball life last October when he gave up the first walk-off grand slam in World Series history to Freddie Freeman.

In a new uniform and a new pennant race on Saturday night, Cortes faced his Dodgers demons head-on – and he came out smiling and left the Dodgers’ hot-and-cold hitters shaking their heads again.

The veteran left-hander produced six brilliant innings of one-hit ball while his San Diego Padres surged past the Dodgers into sole possession of first place in the NL West with a 5-1 victory.

Cortes took a perfect game into the sixth inning, flummoxing the Dodgers’ high-priced lineup and combining with three relievers on a two-hitter. But he didn’t see this stellar performance as redemption for his role in Freeman’s now-iconic slam at Chavez Ravine and the Dodgers’ ensuing five-game victory over his New York Yankees.

“Obviously there’s a history,” Cortes said. “Everybody knows about it. It (stinks) as a player to go through those moments, but the good thing about baseball is that you always have another opportunity. Once the opportunity comes, you try and make the best out of it, and that’s what I did today.”

With a sellout crowd at Petco Park cheering him on in just his fourth start for the Padres, Cortes coolly retired the Dodgers’ first 16 hitters. He struck out three and didn’t walk a batter while slicing through the Dodgers’ collection of MVPs and standout role players with a crafty mix of pitches – and nothing faster than 92.1 mph.

“That was tremendous,” Padres manager Mike Shildt said. “We’re getting to know him, and it just feels like once he gets in a rhythm, he’s really good. He got in a rhythm right from the very first batter, and he just carried it through. It was a fantastic effort through six.”

The Dodgers couldn’t even get on base until Miguel Rojas got a one-out single in the sixth. Cortes calmly regrouped, retiring Shohei Ohtani for the third time on a flyball to end the inning and his night.

In the first two games of this series, the Dodgers have managed only two runs – both via home runs from rookie infielder Alex Freeland – and five hits.

“[We need to] find a way to move the line forward, get hits, spoil pitches, compete,” Dodgers manager Dave Roberts said. “There’s a different level of trying. Everyone’s trying. But I think that [we need] the next level, of going with whatever swing you have that particular night and fighting and willing yourself to get some hits, get on base, create innings and score runs.

“It’s not a lack of talent. Certainly not a lack of try. But we got to do more,” Roberts added. “You got to kind of understand what’s happening in a ballgame and make your adjustments.”

Cortes dared the Dodgers to take a patient approach, to shorten up their swings and take what he was giving them as he worked both sides of the plate.

“We are who we are. We’ve got a lot of guys that can leave the ballpark and that can hit homers,” Rojas said. “But we all know, too, that we can play better baseball than the way that we’ve been playing the last couple days. I feel like the offense is kind of inconsistent at times. We can always get better. We all know we need to get better if we want to win games in a consistent way.”

Freeland’s pinch-hit homer in the eighth was the only damage the Dodgers did against the Padres’ vaunted bullpen, but the Padres answered with Xander Bogaerts’ two-run double off of Justin Wrobleski in the eighth.

Roberts stressed a team-first approach at the plate for his hitters.

“This time of the season, it’s not about the mechanics, your swing,” he said. “It’s about how, ‘Can I help the team win?’ … We’re at the end of August. It’s just about getting the job done and finding a way to find some production.

“You have to, again, take what the pitcher gives you and try to create something. You can’t always go for that big swing. You got to kind of shorten up [sometimes]. We have it in there, and we do it at times. But I just don’t see us doing that collectively.”

Rojas didn’t disagree.

“I feel like a lot of swings that we took today weren’t really good swings to get on base,” Rojas said. “It was a little more to do damage early in the count. And [Cortes] was able to capitalize on that.”

Dodgers starter Tyler Glasnow (1-2) yielded two runs and three hits with four walks in four innings on his 32nd birthday.

Glasnow started well, but San Diego rallied in the fourth. Laureano, another trade-deadline acquisition, delivered a bases-loaded single before Jake Cronenworth’s sacrifice fly.

Glasnow is winless in 12 starts since March despite pitching fairly well.

Aces collide in the series finale Sunday when the Dodgers’ Yoshinobu Yamamoto (10-8, 2.90 ERA) faces the Padres’ Nick Pivetta (13-4, 2.81).

If the Dodgers avoid being swept, they will be back in a first-place tie. If they lose, they will face a two-game deficit in the standings with 31 games to go.

“Let’s just get back to being who we are, and doing those little things; scratching and clawing; finding ways and willing yourself, your team, your offense to score some runs,” Roberts said. “I do believe that that kind of desire will manifest itself. I do.”

NEW GUY DELIVERS

Cortes’ performance was even more impressive because he is still getting to know his teammates and coaches with the Padres, who acquired him from Milwaukee at the July 31 trade deadline in a flurry of moves that have significantly improved an already strong roster.

The Yankees traded Cortes to the Brewers last winter in a package for closer Devin Williams, but Cortes made only two starts for Milwaukee before missing four months with an elbow injury.

Cortes might not have had a role with MLB-best Milwaukee, but he has fit perfectly in a hole in the Padres’ rotation. He gave up four runs in the first inning last Monday against San Francisco, but Cortes has allowed only three earned runs in his other 20 innings for San Diego.

Cortes knows he has landed with a team that could give him a chance to write a new October history, and he’s eager to see how far the Padres can go.

“These guys are resilient,” Cortes said. “They’re not at the top of the standings for no reason. Even long before I got here, watching them from the East Coast, it’s a team that battles, a team that goes out there and plays hard. Now being part of them, you can tell how everybody is here together. It’s a camaraderie, and everybody is just trying to win.”