BALTIMORE – The Yankees flirted with disaster Wednesday night against the Orioles, only to be bailed out by Brett Gardner’s clutch two-out, two-run single in the ninth.

They were not as fortunate Thursday, taking a brutal 3-2 loss to the Orioles in 10 innings on a rainy night at Camden Yards.

It was a damaging loss for the Yankees (82-65), who had a chance to put at least a tiny bit of distance between themselves and the Blue Jays (82-64) and Red Sox (83-65) in the American League wild-card chase.

After the Yankees, whose three-game winning streak came to an end, went 1-2-3 in the 10th, stranding Gardner at second, the Orioles (47-99) won it in the bottom half against Wandy Peralta on a one-out, bases-loaded single by Austin Hays, who put Baltimore ahead with an eighth-inning two-run homer Wednesday night only to see his bullpen blow it.

The Yankees, getting a brilliant outing from Jordan Montgomery, who struck out a career-high 12, took a 2-1 lead into the ninth.

Clay Holmes, who pitched a 1-2-3 eighth and came back for the ninth with closer Aroldis Chapman unavailable having worked the previous three games, struck out Ramon Urias to start the final inning.

But Holmes, looking for his first career save, allowed a one-out single to DJ Stewart. Pinch runner Kelvin Gutierrez went to second on a wild pitch and advanced to third on Pat Valaika’s groundout to third. With Austin Wynns at the plate and the count 2-and-2, Holmes threw another wild pitch, which allowed Gutierrez to score the tying run.

The ugly loss to a degree overshowed a terrific outing by Montgomery, who had next to nothing his last time out, Friday night against the Mets, when he failed to get out of the fourth inning of a blowout loss.

The lefthander experienced almost the complete opposite Thursday night.

With Nestor Cortes Jr. striking out 11 Tuesday night, Montgomery’s performance gave the Yankees back-to-back starters recording 10 or more strikeouts. f

Montgomery, who came in 5-6 but with a 3.71 ERA, allowed one run and four hits over 6 2/3 innings, the one run coming on Ryan Mountcastle’s homer to lead off the sixth, which cut the Orioles’ deficit to 2-1.

The unsteady Yankees bullpen appeared as if it would get the job done from there, with the unusual combination of Albert Abreu, Joely Rodriguez, and Holmes taking the Yankees within a strike of completing a three-game sweep.

The run support issue the 28-year-old has dealt with pretty much all season continued, though his overall excellence Thursday overcame it. Montgomery, who came in having allowed three earned runs or fewer in 21 of his 26 starts but entered the day having received three runs or fewer of support in 21 of his 26 starts, started racking up the strikeouts early, recording two in each of the first three innings and three in the fourth to give him nine through four.

Montgomery, who received a total of 12 runs of support over his previous 13 starts, didn’t see that total increase appreciably Thursday as he departed with one on and two outs in the sixth and a 2-1 lead. Abreu struck out pinch hitter DJ Stewart to end the sixth, allowed a leadoff single to Pat Valaika in the seventh but retired two straight. Rodriguez, a lefty, got the dangerous Cedric Mullins to ground out to end the seventh.

The Yankees' runs came on Joey Gallo's homer in the second and Gio Urshela's RBI double in the same inning.

More Yankees headlines