For 6 2⁄3 innings Monday night, Angels righthander Matt Shoemaker mainly had Yankees hitters spinning on their heels and walking back to the dugout. He faced just two more than the minimum number of batters and was protecting a two-run lead.

Then it was all gone in the space of three pitches, the first a 3-and-2 splitter with two outs in the seventh that Brian McCann pulled into the second deck in rightfield and the third another splitter that Starlin Castro pulled into the leftfield stands to tie the score.

Shoemaker returned for the eighth and again got the first two outs, but he gave up singles by Jacoby Ellsbury and Brett Gardner and was lifted. Lefthander Jose Alvarez promptly gave up an opposite-field three-run homer to Carlos Beltran that produced a 5-2 Yankees victory at Yankee Stadium that was among their most uplifting wins all season.

“Their pitcher was pitching a great game,” Beltran said. “He made a couple of mistakes and we capitalized . . . There’s no doubt he was dominating us.”

McCann had been struggling badly and was 1-for-19 on the Yankees’ recent road trip. Just before his home run, he clobbered a fastball down the rightfield line that had home run distance but curved foul. The groans of a crowd of 34,648 turned to cheers moments later when he hit the home run that broke the spell cast by Shoemaker (3-7), who had a 1.59 ERA in his previous three starts.

“It was nice,” McCann said of seeing his hard work pay off. “I was seeing the baseball, but it was popping up or not going where I think it should. [Shoemaker] had a good splitter tonight, but it was 3-2. He had to throw a strike, and I didn’t miss it.”

advertisement | advertise on newsday

After six innings of feeling they weren’t close, that swing put the Yankees back in the game. Castro said the Yankees felt bad about the lack of run support for their starter, Masahiro Tanaka, who allowed two runs and six hits in seven innings, but they could do little against Shoemaker, who was commanding three pitches.

Following McCann, Castro said, “I tried coming to the plate looking for one pitch to hit. He was throwing strikes. He threw a splitter in the middle of the plate, and I drove it.”

Tie game.

Shoemaker opened the eighth with two outs, but Ellsbury was the one Yankee who had his number. His single was his third hit of the night. Gardner singled to send Ellsbury to third, and that brought the Yankees’ most consistent hitter to the plate to face Alvarez.

Masahiro Tanaka #19 of the New York Yankees pitches in the first inning against the Los Angeles Angels at Yankee Stadium on Monday, June 6, 2016 in the Bronx Borough of New York City. Photo Credit: Jim McIsaac

“I didn’t know much about him,” Beltran said.

Yankees videos

“Honestly, it was a great job by Ellsbury and Gardner to get on base and give me an opportunity. I was trying to stay inside. The first pitch was a cutter that was a good pitch. The second was a fastball in the middle.

“I wasn’t thinking home run. I was thinking base hit. It was high, and I didn’t know if the rightfielder could get it. It was fun to see it leave . . . Of course, it’s a boost for our team.”

Unlike Sunday, the Yankees’ bullpen made the lead stand up as Andrew Miller (3-0) struck out the side in the eighth and Aroldis Chapman closed the deal in the ninth.

Tanaka gave up a run in the first inning when Yunel Escobar singled and scored on a two-out single by Albert Pujols.

Gregorio Petit led off the third with a ground-rule double, moved to third on Escobar’s sacrifice and scored on a sacrifice fly by Kole Calhoun.

advertisement | advertise on newsday

But the Yankees’ bats finally showed up.

“There’s power in this lineup,” manager Joe Girardi said.

“It hasn’t come out the way it’s capable of, but it comes out quickly.”