BALTIMORE — It would have been a gift run, but one Joe Girardi believed the run-starved Yankees deserved. And with Masahiro Tanaka and Kevin Gausman throwing zeroes, it was one his club needed.

And so a non-balk call by third-base umpire Chris Guccione with a runner on third and one out in the fourth inning incensed Girardi, who soon was ejected. Starlin Castro would be stranded at third, and there then were few scoring chances by either club until the 10th inning.

That’s when the Orioles finally won it on Pedro Alvarez’s sacrifice fly off Andrew Miller, handing the Yankees a dispiriting 1-0 loss Thursday night that closed a dispiriting 2-7 trip.

It was the 19th time in 26 games that the Yankees (9-17) have scored three or fewer runs (they’ve gone 3-16 in those games) and the 14th time they have scored two or fewer (0-14).

Against righthander Johnny Barbato, Hyun Soo Kim opened the 10th with an infield single. Kim went to third on Jonathan Schoop’s single to left. As pinch runner Nolan Reimold replaced Kim, in came the lefthanded Miller to face the lefthanded-hitting Alvarez, who lifted a fly ball to medium center. Reimold easily beat Jacoby Ellsbury’s weak, off-line throw to the plate.

With two outs in the top of the ninth and Castro on second, Brian McCann swung through a 3-and-1 pitch and Matt Wieters picked off Castro.

Defense saved the Yankees in the ninth. With one out and pinch runner Joey Rickard on first against Dellin Betances, Wieters skied one deep to right. Dustin Ackley made a leaping catch against the wall, robbing Wieters of an extra-base hit, and when Rickard wandered all the way to second, thinking the ball had hit the wall, he was doubled off first.

McCann walked to start the 10th but pinch runner Brett Gardner was stranded as Zach Britton struck out Mark Teixeira, Carlos Beltran and Ackley.

Tanaka turned in by far his best start of the season, not to mention the best by any Yankees starter in 2016. The righthander followed up the Yankees’ 7-0 shutout Wednesday night by allowing five hits and a walk in eight innings, striking out seven, and lowered his ERA to 2.29.

“Maso was great,’’ Teixeira said. “Unfortunately, Gausman was just as good . . . It’s kind of been the story of the season. We just haven’t hit. It’s not rocket science. We just need to execute better.”

Gausman went eight shutout innings and lowered his ERA to 1.42. He allowed three hits and did not walk a batter.

Castro doubled into the leftfield corner on the first pitch of the fourth and went to third on McCann’s fly to center. Teixeira followed with a sharp grounder to first, and Davis held Castro at third before stepping on the bag.

With Beltran at the plate, Girardi walked to the third-base end of the dugout and began jawing with Guccione, arguing that Gausman had committed a balk earlier in the at-bat. The two yelled and gestured at each other throughout the at-bat, which ended with Beltran popping out.

As the Orioles came off the field, the shouting continued and Guccione, responsible for Girardi’s first ejection as Yankees manager back in 2008, tossed him. After an animated on-field argument, Girardi began walking away from Guccione, who cupped one hand over his mouth to yell something more at Girardi. Girardi stopped in his tracks, spun back and verbally sparred some more with the umpire before departing.

Girardi’s contention was that Gausman never came set in the stretch. “He’s balking,’’ he said. “They can say he’s not trying to deceive the runner, but he’s not stopping . . . “[Guccione] threw me out when I was coming out to get an explanation. That bothered me.’’