Yankees' Gary Sanchez reacts as he heads to first to...

Yankees' Gary Sanchez reacts as he heads to first to round the bases after hitting a three-run home run during the ninth inning of a baseball game against the Baltimore Orioles, Monday, May 20, 2019, in Baltimore. Credit: AP/Nick Wass

BALTIMORE — Not even another awful outing by J.A. Happ could doom the Yankees.

Not against the terrible Baltimore Orioles.

Despite Happ helping to plunge the Yankees into an early five-run deficit, they rallied against the sport’s worst outfit not named the Marlins to post a 10-7 victory in front of 16,457 at Camden Yards.

“We won in spite of me tonight,” said Happ, who was gone after 3 2/3 innings in which he allowed six runs and nine hits. “We fought back every inning.”

Gary Sanchez’s three-run homer in the ninth off Mychal Givens broke a tie and propelled the Yankees to a 10-7 victory, capping a comeback from 6-1 and 7-3 deficits. The victory put the first-place Yankees (29-17) a game in front of the Rays in the AL East.

“We have a great team here,” Sanchez said through his translator. “No matter many runs we’re down, we’re going to battle.”

The Yankees, who scored two runs in the sixth and seventh innings, a single run in the eighth and four in the ninth, got a two-homer performance by Gleyber Torres, who has been Aaron Judge-like against the Orioles this season, with eight of his 10 homers coming vs. Baltimore.

New York Yankees' Gary Sanchez, right, celebrates his three-run home...

New York Yankees' Gary Sanchez, right, celebrates his three-run home run with Luke Voit (45) during the ninth inning of a baseball game against the Baltimore Orioles, Monday, May 20, 2019, in Baltimore. (AP Photo/Nick Wass) Credit: AP/Nick Wass

The second of Torres’ homers, a two-out shot in the eighth off Givens, made it 7-6. That gave the 22-year-old a .486/.538/1.257 slash line, with eight homers and 10 RBIs, in nine games against Baltimore.

“I just try to do my job,” said Torres, whose homer in the second off Andrew Cashner got the Yankees on the board. “I’m focused every game. That’s just [how it goes].”

Sanchez’s monstrous two-out blast gave the catcher 13 on the season. Brett Gardner and Cameron Maybin started the rally with singles and Aaron Hicks’ sacrifice fly tied it at 7. Before Sanchez came to the plate, Luke Voit walked, his at-bat extended when Orioles catcher Pedro Severino missed a sky-high foul pop by some 10 feet.

“I hit it really high and I know those are tough ones for catchers,” said Voit, who had his own misadventure with one, dropping a foul pop in the sixth inning that led to a run that made it 7-3. “It’s baseball. Weird things happen.”

A walk and an error by third baseman Gio Urshela in a shaky ninth allowed the Orioles (15-32), who have lost 10 of 12, to get the tying run to the plate against Aroldis Chapman. But the closer, who opened the inning with a strikeout, struck out the last two batters for his 12th save in 13 chances.

Happ hasn’t been very good against most everyone so far and Monday night he was battered by the Orioles. The 36-year-old surrendered two homers — giving him 13 allowed in 10 starts — to help put the Yankees in the 6-1 hole. Of the Orioles’ 13 hits overall, eight went for extra bases.

“Tonight was a tough one,” Happ said. “I don’t know that I have an answer for it. They hit the bad pitches, they hit the good pitches. I just got beat tonight.”

Baltimore tagged Happ (3-4, 5.16) for a pair of runs in the first — leadoff man Hanser Alberto doubled, the first of his four hits — and drove the pitcher from the game by the fourth inning.

After Luis Cessa escaped a bases-loaded, one-out jam in the fifth, the Yankees started their comeback in the sixth. DJ LeMahieu led off with an infield single and Hicks walked. After Voit grounded into a fielder’s choice that moved the runners, Sanchez stung a single to center to make it 6-2 and put Hicks on third. Kendrys Morales’ groundout to short brought in Hicks to make it 6-3.

“There was a good vibe, even though things weren’t going our way early,” Aaron Boone said. “There was that theme in the dugout, ‘let’s chip away at this.’ We were able to hang in there enough.”

More Yankees headlines

Newsday LogoCovering LI news as it happensDigital AccessOnly 25¢for 5 months