– When he was finally done for the day, Tyler Duffey stalked off the mound, muttering to himself, then yelled out loud, clearly angry about his performance. Another messy, run-filled disaster? A well-deserved ticket back to Rochester?

Nope, he was furious that Mark Teixeira nicked up his shutout. Like Tolstoy finding a typo in “War and Peace.”

Duffey, the threat of demotion to the minors surrounding him like the humidity on this 90-degree afternoon, was brilliant in his Yankee Stadium debut Sunday, retiring the first 17 batters he faced, giving up only two hits over eight innings and ending a pair of ugly three-game losing streaks — his own and his team’s — as the Twins beat the Yankees 7-1.

“Throw the ball over the plate — it does wonders,” Duffey said after the most dominating, and timely, outing of his career. “Mainly, I was able to spot my fastball well, and everything else worked off that.”

Duffey’s teammates rallied to his cause, too, by smacking six home runs in this homer-friendly ballpark. Danny Santana, Eduardo Nunez and Juan Centeno all contributed solo shots, and in a memorable sixth-inning power display, Brian Dozier, Trevor Plouffe and Max Kepler went (relatively) deep, back-to-back-to-back.

“I keep telling you guys, and it’s true — hitting is contagious,” Dozier said after reaching double digits in homers for the fourth consecutive season. “When guys start heating up around you, you kind of want to do the same, and good things happen.”

The Twins needed some good things, considering they own the worst record in baseball and had lost 10 of their past 11 games to the Yankees, including the first two games of this series. They got it with their power blitz, the 11th time in franchise history they have had at least six home runs. It’s their first six-homer game since the second game of a doubleheader July 6, 2007, against the White Sox in Chicago, when Justin Morneau bashed three and Torii Hunter, Michael Cuddyer and Jeff Cirillo also connected.

But it was Duffey’s day that was most thrilling for the Twins, considering it came after he had seven consecutive starts of giving up four or more runs. His June ERA was 9.82, and manager Paul Molitor hesitated for a day after Duffey’s three-inning, six-run drubbing vs. Philadelphia on Tuesday before determining the 25-year-old would get another chance.

Molitor didn’t hesitate this time. “You could say he earned another opportunity to get back out there,” he deadpanned. “I’m sure he’s thought about it. I don’t know how much pressure he put on himself to pitch well. … You put too much exterior pressure on yourself, pitching to save your spot, that can be more distraction than helpful.”

Duffey (3-6) didn’t seem distracted. Using mostly fastballs to get ahead the first time through the order, he got six groundouts. Then he started mixing in his curveball and changeup, and he racked up four strikeouts in five batters. And when Chase Headley grounded into the Twins’ shift to give Duffey 17 consecutive outs, there was noticeable we’re-watching-history anticipation in a ballpark that has already seen plenty.

“I looked up and I was like, ‘Wait, they get anybody on base? I don’t think anyone’s been on base,’ ” Dozier said. “I might have jinxed it myself.”

Duffey left a 1-0 changeup too high to ex-teammate Aaron Hicks, and the perfect game was gone. Hicks lined it into the right-field corner for a double, and Duffey made sure he heard about it.

“As I walked past, I said, ‘Why couldn’t you swing through it like the first one?’ ” Duffey said. “I made sure to keep my head down so nobody could see that.”

Everyone could see his emotions when Teixeira led off the eighth with a line drive into the right-field seats, a hit that would have been a double at Target Field. When the inning ended, Duffey strode angrily into the dugout.

“We had a little moment there. I had to let him know, yeah, we get it, you have a potential shutout maybe going back out for the ninth,” Molitor said. “It’s good to have goals like that. You just don’t want to see a 6-1 lead in the eighth inning, when you’ve given up two hits, to cause an overreaction because a guy got hold of a breaking pitch. I think he gets that. It just speaks to what he expects out of himself.”