SAN DIEGO — On Wednesday night, the Yankees stunned the Rangers with a six-run ninth inning that snatched victory from a sure defeat.

They nearly pulled off a similar victory Friday night against the woeful Padres, but a four-run rally left them just short in a 7-6 loss in front of 41,321 at Petco Park.

Meanwhile, put Nathan Eovaldi fully in the train-wreck column — with no ending in sight. The righthander turned in a sixth straight poor outing, helping to create a deficit the Yankees couldn’t overcome..

Brian McCann’s 13th homer, with one out in the sixth, made it 6-2. In the Yankees’ four-run ninth, Alex Rodriguez had a pinch-hit RBI single, Didi Gregorius added an RBI double and Aaron Hicks had an RBI groundout, and a wild pitch allowed Gregorius to score. Pinch hitter Carlos Beltran added a double and got to third with two outs, but Brett Gardner grounded out to short to end it.

Eovaldi entered the night 6-5 with a 5.19 ERA, including a 1-4 record and 8.65 ERA in his previous five starts, allowing 10 home runs in that stretch.

Eovaldi, who allowed 10 home runs all of last season, gave up four of those to baseball’s worst team in his previous outing against the Twins. And last night, he allowed two of them while giving up seven hits overall and six runs in 4 1⁄3 innings.

After Eovaldi was yanked from the game in the fifth, YES cameras showed Joe Girardi in a decidedly one-sided conversation with him in the dugout.

Eovaldi, of course, wasn’t the only problem for the Yankees (39-40), who could not start off this 10-game, three-city trip by building on the momentum of two straight walk-off victories over the Rangers.

They had four hits in six innings against righthander Colin Rea, who came in 4-3 with a 5.05 ERA for the Padres (35-46). Rea, who needed 46 pitches to get through a ragged first two innings, allowed two runs (one earned).

Jacoby Ellsbury led off the first with a groundout to short but was awarded first on catcher’s inference, the seventh one he’s drawn this season. No major-leaguer had drawn more than six since Roberto Kelly had eight in 1992.

Gardner’s groundout to first and Mark Teixeira’s bloop single to center put runners at the corners. Rea struck out McCann looking but walked Starlin Castro to load the bases for Chase Headley, who grounded out.

The Padres took the lead in a three-run bottom half. Wil Myers (2-for-3 with a homer) walked with one out and went to second on a two-out single by former Yankee Yangervis Solarte. Melvin Upton Jr. then had an RBI single and Derek Norris added a two-run double to make it 3-0.

The Yankees came back in the second. Gregorius, coming off a June in which he hit .337, started the rally with a single. After Hicks flied out, Gregorius went to second on a passed ball with Eovaldi at the plate. Eovaldi struck out but Ellsbury singled sharply to right to make it 3-1.

The Padres got the run back in the bottom of the second when Ryan Schimpf, who came in with a .183/.289/.172 slash line in 13 games, drove a 2-and-2 offspeed pitch over the wall in right-center for his first homer of the season, making it 4-1.

Travis Jankowski (1-for-4), who starred at Stony Brook University and was on the team that went to the 2012 College World Series, led off the fifth with a single, bringing Myers to the plate. He obliterated a full-count fastball to right-center, and his 19th homer gave the Padres a 6-1 lead.