NEW YORK — Tyler Duffey never thought for a moment that he was pitching for his spot in the Minnesota rotation. The idea that he was pitching a perfect game at Yankee Stadium, yep, that was in his head.

The struggling Duffey set down his first 17 batters and wound up throwing two-hit ball for eight innings while the Twins backed him with six home runs to beat New York 7-1 Sunday.

"I knew what was going on the whole time," Duffey said.

Brian Dozier, Trevor Plouffe and Max Kepler hit consecutive homers in the sixth inning to help end a three-game skid. Danny Santana, Eduardo Nunez and Juan Centeno also connected in the Twins' first six-homer game since 2007.

Duffey (3-6) pitched perfect ball until Aaron Hicks lined a clean double into the right-field corner with two outs in the sixth. Hicks picked on a changeup, a pitch he'd missed earlier in the game.

Walking back to the dugout after the inning ended, Duffey passed Hicks, tapped his former Twins teammate with his glove and had a quick word with him.

"I said, 'Why couldn't you just swing through that one like the first one?'" Duffey said.

Facing all the Yankees batters for the first time, Duffey struck out eight, walked none and stopped a team that had won three in a row. The 25-year-old righty began the day with a 6.18 ERA, was 0-3 in his last five starts and had been hit hard in seven straight outings.

"You could say he earned another opportunity," Twins manager Paul Molitor said.

Mark Teixeira hit a leadoff homer in the Yankees eighth. Duffey fanned the next three batters to wrap up his longest outing in the big leagues.

Last season, in his second game in the majors, Duffey took a no-hit bid into the sixth before Cleveland's Francisco Lindor doubled with one out.

No one has ever thrown a perfect game against the Yankees. The last pitcher to toss a complete-game no-hitter against them was Hoyt Wilhelm for Baltimore in 1958.

Duffey has experience with perfection, sort of. In his first pro start, for Class A Cedar Rapids in 2013, he threw seven perfect innings before being pulled because of a pitch count.

"It was in the back of my mind," he said.

The Twins have won just two of their last 12 against New York. Brandon Kintzler completed the combined two-hitter.

"You win a series here, but it's frustrating because we had a situation where we won three in a row there, we weren't able to win the fourth. You win two in a row, you're not able to win the third," Yankees manager Joe Girardi said.

Nathan Eovaldi (6-5) lost to the Twins for the second time in eight days. The hard-thrower is winless in five starts, tagged for 10 homers and 25 runs in 26 innings during that span.

Santana put the Twins ahead with a solo homer in the third, then they teed off in the sixth after a two-out walk to Joe Mauer.

Dozier, Plouffe and Kepler gave Minnesota its first set of back-to-back-to-back homers since 2014, when Chris Parmelee, Oswaldo Arcia and Eric Fryer did it.

Eduardo Escobar was up next and a booing crowd hollered even more loudly when he hit a hard smash that sailed far foul. He grounded out to end the homer streak.

Eovaldi gave up a career-high four home runs.

TRAINER'S ROOM

Twins: Plouffe returned to the lineup after missing two games because of a strained groin. He shifted over from 3B and made his second start of the season at 1B.

ROSTER MOVE

The Yankees recalled righty Luis Cessa from Triple-A and sent down RHP Nick Goody. Girardi said the move will let him use LHP Richard Bleier as a lefty specialist. Bleier relieved in the seventh and struck out the lefty-swinging Kepler. Cessa pitched 1 2/3 innings and gave up Nunez's homer.

BIRTHDAY

Former Yankees star Derek Jeter celebrated his 42nd birthday.

UP NEXT

Twins: After a day off, RHP Kyle Gibson (0-5, 6.05 ERA) and Minnesota visit the White Sox and LHP Jose Quintana (5-7, 3.04). Gibson will make his eighth start of the season.

Yankees: RHP Ivan Nova (5-5, 5.18 ERA) starts at home Monday night against AL West-leading Texas and RHP Chi Chi Gonzalez, who pitches in the majors for the first time this year. Nova gave up a season-high six runs vs. Colorado in his last start.