Yankees rightfielder Aaron Judge and first baseman Greg Bird walk...

Yankees rightfielder Aaron Judge and first baseman Greg Bird walk off the field as the Orioles celebrate after a game on Tuesday in Baltimore. Credit: AP / Patrick Semansky

BALTIMORE — The times this season the Orioles have resembled a quality major-league team are few and far between.

Except, oddly, against the Yankees.

They’ve done just fine there.

The Orioles, who came into this series 41 games under .500, made it five victories in nine tries vs. the Yankees Tuesday night, winning 6-5 on Jonathan Schoop’s two-out, bases-loaded single in the ninth off Dellin Betances that scooted past Greg Bird’s glove.

“I wish I knew,” Aaron Judge said of Baltimore’s success against his team this season. “If we knew, we’d be able to stop it.”

The Yankees (59-31), who have lost two of three in this series, fell 3½ games behind the Red Sox, who have given no indications they’re going to cool off.

“We had a bad series early in the year [against them] so I wouldn’t categorize it as that just yet,” Aaron Boone said of a Yankees-struggle-against-the-Orioles narrative. “And then we’ve lost two tough games here back-to-back days where we’ve had leads. They have good players over there.”

Betances (1-3) didn’t get a borderline pitch against Caleb Joseph to start the ninth, then hit the catcher with a pitch. After Tim Beckham flied to right, Adam Jones punched a double down the rightfield line.

Manny Machado, whom the Yankees might try to acquire strictly to keep their pitchers from having to face him again — he already had two homers in the game — was intentionally walked to load the bases for Mark Trumbo, who struck out.

But Schoop slashed one that Bird couldn’t glove, the play scored a hit, providing the Orioles (26-66) with the victory.

“A play I want to make,” said Bird, who drove in four runs, three of them on a three-run homer in the fifth that gave the Yankees a 3-2 lead. “Big spot there, it’s a play I want to come up with. He put a decent swing on it. It just kind of rode up and I just didn’t get it up in time.”

Betances didn’t complain about the borderline pitch, or Bird not coming up with the ball.

“I thought it was a strike, maybe it was a little away, but I have to make a better pitch on the next one,” Betances said.

Of the Bird play, Betances said: “I don’t put the blame on any of my teammates.”

Bird saved Masahiro Tanaka from taking a loss in his first start after a month on the disabled list. Tanaka, on a pitch count of 80, didn’t last long enough to qualify for a win.

The righthander showed some signs he could be reliable down the stretch but couldn’t avoid what’s plagued him: the long ball.

Tanaka, on the disabled list since June 9 with hamstring strains in both legs, allowed three runs and six hits in 4 1⁄3 innings. Handed the 3-2 lead by Bird, he served up a fastball that Machado hit out to tie it.

“Disappointed in that pitch,” Tanaka said through his translator. “I can’t do that. I have no excuse for that.”

After the Yankees took a 5-3 lead in the seventh on a sacrifice fly by Bird and an RBI single by Neil Walker, Machado tied it in the bottom half with a two-run shot off Chad Green. It gave Machado 23 homers this year including six in nine games against the Yankees, and 20 against them in 62 games since 2015, more than any player in that span, according to baseball researcher Katie Sharp.

“I tried to go up in the zone with it,” Green said. “With a hitter like that, you can’t miss in the zone. That’s why he’s one of the best hitters in the league.”

SUBSCRIBE

Unlimited Digital AccessOnly 25¢for 5 months

ACT NOWSALE ENDS SOON | CANCEL ANYTIME