NEW YORK — A year ago, Justin Smoak became the first Toronto player to ever hit a grand slam in the Bronx.

On Tuesday night, his bid to repeat the feat at Yankee Stadium fell just short.

Brett Gardner made a leaping catch at the top of the left-field wall on Smoak’s bases-loaded drive for the final out, and the Blue Jays fell to wild card-contending New York 7-6.

“We were two inches from scoring two more runs or maybe three,” Toronto starter Aaron Sanchez said.

A scrambly September game with October implications seesawed to the last swing, and turned at the end in favor of the Yankees. New York won its third in a row and sent Toronto to its fourth loss in five games. The Blue Jays fell back into a tie for first place in the AL East with Boston.

The Blue Jays had already scored twice in the ninth off Dellin Betances when they loaded the bases with one out. Blake Parker, the eighth New York pitcher, suddenly became an unlikely closer, and he struck out Kevin Pillar.

Smoak was up next, and he sliced a drive to deep left.

“Thought it might have had a chance,” Smoak said, later adding, “put a good swing on it, barreled it.”

Gardner ran back, jumped and corralled the ball at the top of the fence as he banged into the padding. He immediately leaped in the air to celebrate as the Yankees rushed out to congratulate him. A few minutes later, a replay of the catch drew another ovation from the fans.

“Gardner, he’s been known to do that,” Blue Jays manager John Gibbons said.

The 29-year-old Smoak and 33-year-old Gardner know each other from growing up in South Carolina.

“He’s an old man,” Smoak said, smiling.

Tyler Austin’s two-run homer in the seventh off Sanchez put the Yankees ahead 3-2. Pillar lined a two-out, two-run double in the eighth that gave the Blue Jays a 4-3 edge.

The Yankees then rallied for four runs in their half for a 7-4 lead, capped by Chase Headley’s two-run homer. The drive off Jason Grilli (5-5) left the reliever bent over at the mound in frustration.

With the Yankees running out of time to chase a playoff spot, manager Joe Girardi spared no expense with his staff. Chasen Shreve (2-1) wound up with the win and Parker got his first save since 2013 with the Cubs.

Betances made it interesting in the ninth, walking the first two batters while working his third straight day. Edwin Encarnacion and Melvin Upton got RBI singles on infield hits to pull Toronto within a run.

Sanchez threw seven innings and left with a 2.92 ERA. The Blue Jays are trying to limit his workload, giving the 24-year-old All-Star extra rest. He already has thrown more than 36 innings over his previous high in any season.

Encarnacion hit his 37th homer into the second deck for Toronto and tied his career high with 111 RBIs. He started the day tied with Angels slugger Albert Pujols for the league lead in RBIs.

ALMOST

Sanchez nearly struck out the side on nine pitches in the fifth. He fanned Aaron Judge and Austin and got two quick strikes on Gardner before bouncing a changeup. Gardner eventually reached on an error.

NICE GRAB

Blue Jays announcer and former manager Buck Martinez neatly snagged a foul ball by Bautista that flew into the broadcasting booth. No surprise — he was a catcher for more than 17 seasons in the majors. He tossed the souvenir to kids.

TRAINER’S ROOM

Blue Jays: SS Troy Tulowitzki was back in the lineup, a day after manager John Gibbons said he needed a game to rest.

UP NEXT

Blue Jays: RHP Marcus Stroman (9-6, 4.58) has allowed eight earned runs in 12 innings over his last two starts.

Yankees: RHP Bryan Mitchell was promoted from Triple-A before the game and is likely to make his Yankees debut this year.