The Yankees' Tyler Wade and Gleyber Torres celebrate after they both...

The Yankees' Tyler Wade and Gleyber Torres celebrate after they both scored on a two-run double by Brett Gardner during the ninth inning of a game against the Orioles on Wednesday in Baltimore. Credit: AP/Julio Cortez

BALTIMORE — Brett Gardner saved the Yankees from what would have been among their most crushing defeats of the season.

Which is saying something.

After reliever Chad Green, troubled by the long ball all season, gave up a two-out, two-run homer by Austin Hays in the eighth inning that put the Yankees behind by a run, Gardner’s two-run bloop single with one out in the ninth helped them take a 4-3 victory over the Orioles on Wednesday night in front of 10,402 at Camden Yards.

"That’s the guy you want up there," said Tyler Wade, who pinch ran in the ninth, stole third on a double steal and scored along with Gleyber Torres on Gardner's hit. "He’s been in those situations all the time, for 10, 11 years. His heartbeat’s really slow. He knows exactly what he needs to do and he did it tonight."

Both the Blue Jays and Red Sox had won earlier in the day, so it was a critical comeback for the Yankees, who remained tied with Toronto for the wild-card lead at 82-64 (.562). The Red Sox (83-65), while in a virtual tie with the other two at 18 games over. 500, are a percentage point behind.

The Orioles fell to 46-99.

Orioles righthander Tyler Wells, part of one of the worst bullpens in the game, walked Luke Voit to begin the ninth. Wade pinch ran for him and Torres, who had made a key defensive miscue in the eighth, lined a single to center.

"Just a really tough at-bat he threw up there," Aaron Boone said of Torres. "A big spot there. Helped set us up big time that inning."

After Gary Sanchez flied to center, Wade and Torres executed a double steal against the combination of Wells, not the easiest to steal against, and catcher Austin Wynns, well above the league average in throwing out would-be base-stealers. "Makes my job at the plate a lot easier," Gardner said.

With the infield drawn in, Gardner dumped a 1-and-2 slider into shallow left-center, just beyond the reach of shortstop Richie Martin, to give the Yankees a 4-3 lead. They had not scored since Gio Urshela’s two-run homer in the third made it 2-0 (5-8 Cedric Mullins had leaped high above the centerfield wall to rob Sanchez of a two-run homer in the second).

"You want to be up there with the game on the line," said Gardner, who had three hits and is 12-for-33 with seven RBIs in his last 10 games. "I feel like I’ve been having pretty good at-bats recently."

Aroldis Chapman, pitching a third straight day, struck out two in a perfect ninth for his 27th save in 31 chances.

"These game are so important. They mean a lot to us," Chapman said through his interpreter.

Green, who pitched a scoreless seventh after taking over for Nestor Cortes Jr., could not hold the 2-1 lead he took into the eighth. Wynns led off with a single and reached second when Torres dropped Mullins’ sinking line drive and immediately threw to first instead of at least cutting down the lead runner on what might have been a double-play ball. After a wild pitch moved Wynns to third. Green struck out Ryan Mountcastle for the second out. Then, with the count 0-and-2, Sanchez called for a fastball above the zone and Green didn't get it high enough, allowing Hays' 20th homer. He also had homered in the sixth off Cortes.

"We were in shock, obviously . . . but it’s not over," Cortes said. "Everyone knows the lineup we have and how dangerous we can be."

Cortes lowered his ERA to 2.60, but Green’s implosion cost him a win. The lefthander, whose fastball barely ticks over 90 mph but who keeps opposing teams off balance with his assortment of speeds, deliveries and arm angles, was as good as he’s been as a Yankee. He allowed one run, three hits and two walks in 6 1⁄3 innings in which he struck out a career-high 11 (his previous high was seven).

"Overall, I thought it was as good stuff as he’s had," Boone said. "Stuff-wise, it was special tonight."

More Yankees headlines