A fly ball by Fernando Tatis Jr. just beyond the wall in right field. A line drive by Jake Cronenworth off the painted yellow line on the corner of the Western Metal building. A low liner rocketed off Manny Machado’s bat at 109 mph into the Padres’ bullpen.

Those three home runs — one barely long enough, one barely fair enough, one barely high enough — happened in succession before the Padres made an out on Sunday.

It was an historic display of power.

It was the first time in 40 seasons the Padres have begun a game with three home runs, and it made Yankees starter Gerrit Cole the first MLB pitcher to ever allow three home runs at the start of a game twice.

But it was Luis Campusano’s towering blast to the second deck of seats beyond left field leading off the seventh inning that decided a 4-3 victory over the Yankees.

Cole was hardly touched outside the four home solo runs he allowed in seven innings, and the Yankees scored three runs against Adrian Morejón in the eighth inning to make it tense before Mason Miller worked the ninth inning to earn his 33rd save.

Before the Yankees broke through against Morejón, Michael King turned in his sixth consecutive quality start, the last three of which have been scoreless outings, and Bradgley Rodriguez worked a 1-2-3 seventh.

By winning a series against the Yankees for the first time in five tries since 2019, the Padres remained a half-game behind the Diamondbacks in the race for the National League’s final postseason spot.

The game was far more tense than might be imagined in a contest one team led 3-0 for essentially all of the first seven innings.

But Cole, who had not given up more than three runs in any of his previous 11 starts, fixed whatever the Padres saw in the first inning.

After duplicating something he also did at Minnesota in 2022, allowing the three homers at the start, he retired 21 of the final 24 batters he faced.

Dustin Harris began the second inning by lining a single to right field that caromed off Jasson Domínguez’s glove and rolled to the wall as Harris got to third base standing up.

But Xander Bogaerts grounded out to shortstop, Ethan Salas struck out and Tatis popped out.

That began a stretch in which Cole retired seven straight and 15 of 16 before Luis Campusano led off the seventh inning with a home run to the second deck beyond left field.

Cole got through the seventh to finish his day having allowed the four home runs and two singles.

King allowed successive one-out singles in the second inning, loaded the bases with two outs in the fifth and survived a one-out walk in the sixth thanks in part to Cronenworth diving to spear a line drive just off the ground for the final out.