Credit: Newsday / Thomas A. Ferrara

At first, Brett Gardner wasn’t entirely sure he had it.

Neither was Blake Parker, who threw the pitch that could have been remembered far differently, nor anyone in the home dugout.

The Yankees rallied to beat the Blue Jays, 7-6, on Tuesday night at the Stadium, a wild ride of a victory secured only when Gardner crashed into the wall in left and snow-coned an opposite-field drive by Justin Smoak with the bases loaded.

Finally sure the baseball remained in his glove, Gardner turned football referee at the goal line, jutting his arms upward. Players and staff poured out of the dugout, equal parts excited and relieved.

“Sheer joy,” said Parker, who relieved an ineffective Dellin Betances, who was working a third straight game and left him a bases-loaded, one-out mess, with two runs already in. “Astonished that he caught it. I saw it pop out and go back in.”

“I was worried,” Joe Girardi said when Smoak made contact.

Said Gardner: “I’m just fortunate the ball stayed in.”

But even with their third straight victory, the Yankees (72-65) stayed 3 1⁄2 games behind the Orioles (76-62) for the AL’s second wild card. The Astros (74-64), also ahead of the Yankees, won, too.

Coming into the night, FanGraphs listed the Yankees’ chances of making the postseason at 3.9 percent. Those odds didn’t increase dramatically after the win, though the Yankees did climb within 4 1⁄2 games of the AL-East leading Blue Jays (77-61), who have lost five of their last seven.

“Everyone’s doing their job,” said Didi Gregorius, whose RBI triple off Jason Grilli sparked a four-run eighth inning that turned a 4-3 deficit into a 7-4 lead. “We’re still fighting. We’re not going to give up.”

The rally was capped by Chase Headley’s two-run homer, which provided what proved to be crucial insurance runs.

Rookie first baseman Tyler Austin, who turned 25 Tuesday, gave the Yankees a 3-2 lead in the seventh with a two-run homer off Toronto ace Aaron Sanchez, pretty much dominant to that point.

Sanchez, who came in 13-2 with a 2.88 ERA, had allowed only a solo homer by Brian McCann in the fourth. Struggling rookie Aaron Judge — 26 strikeouts in his last 39 at-bats coming in — hit a two-out single. Then Austin took a fastball the other way, into the bleachers in right-center for his second career homer. He hadn’t gone deep since his debut Aug. 13.

Girardi, without Tyler Clippard who had worked three straight games, tried to piece things together in the eighth, and it did not go well.

Troy Tulowitzki singled off Adam Warren with two outs, and lefty Tommy Layne walked pinch hitter Melvin Upton Jr. In came rookie Ben Heller to face Kevin Pillar, who smashed a fastball off the wall in left-center for a two-run double that made it 4-3.

It was obvious right away in the ninth that Betances, even with a three-run lead, simply didn’t have it. He walked Jose Bautista and Josh Donaldson to start the inning, and it got worse.

The 31-year-old Parker, claimed by the Yankees on Aug. 9 after being DFA’d by the Mariners, came on to face Pillar with the bases loaded and the score 7-6. Pillar was 3-for-3 with a walk, but Parker struck him out looking, setting up the dramatic finish.

“That’s not an easy situation to come into,” Betances said. “I was hoping for the best. I didn’t leave him in a good situation. Parker did a hell of a job.”

Aided by, all agreed, one hell of a catch.

SUBSCRIBE

Unlimited Digital AccessOnly 25¢for 5 months

ACT NOWSALE ENDS SOON | CANCEL ANYTIME