Andrew Miller made his first appearance as Aroldis Chapman’s setup man Tuesday night. It did not go well.

Miller gave up a one-run lead in the eighth inning on Kansas City centerfielder Lorenzo Cain’s third home run of the game.

But the defending World Series champion Royals are not playing like the same team that took out the Mets in five games last year. Kansas City’s bullpen and defense faltered as the Yankees pushed across three runs in the bottom of the eighth for a 10-7 victory at Yankee Stadium.

That made Miller the winning pitcher as Chapman threw a scoreless ninth with one strikeout to earn his first save as a Yankee. Chapman retired Cain on a pop-up to second to end it.

The Yankees, who have won five of seven, improved to 13-18.

“We were struggling to score runs eight, nine days ago,” manager Joe Girardi said. “And all of a sudden, our bats have started to come alive. It very well so could have been a game that we wouldn’t have won. I think guys feel better about themselves. That’s the bottom line.”

With the game tied at 7 in the eighth, Yankees rookie Ben Gamel reached on an error on a routine grounder to Gold Glove shortstop Alcides Escobar. Brett Gardner followed with a go-ahead double to left-center off Kelvin Herrera to score Gamel, who was making his first big-league start.

After Herrera hit Starlin Castro with a pitch, Brian McCann hit a two-run double to give Chapman some breathing room.

It was the first runs allowed this season by Herrera (0-1). Miller (2-0) had been unscored upon as well.

“Unfortunately, I made a bad pitch and had to pay for it,” said Miller, who was charged with his first blown save in seven chances. “Thankfully, Gardy and Mac came through big-time there, the bottom of the eighth, and Chaps ended up closing the door.”

Chapman, who season-opening suspension for violating baseball’s domestic violence policy ended Monday, thrilled the crowd for the second straight night with high heat, including one pitch clocked at 102 miles per hour.

“Very happy to get the save,” Chapman said through his translator. “Hope to get many more.”

Masahiro Tanaka, who fired eight shutout innings in his last outing, gave up six runs (including three home runs) in seven innings. Cheslor Cuthbert hit a two-run homer in the second, Cain smacked an opposite-field shot to right in the third and Cain hit a 435-foot three-run blast to left-center in the fifth to give Kansas City its final lead at 6-5.

“My slider was not good,” Tanaka said through his translator. “It was up and not moving much.”

Still, Tanaka was in line for the win when the Yankees went ahead in the seventh on Dustin Ackley’s two-out RBI single and Aaron Hicks’ go-ahead double.

The Yankees, who were without the injured Mark Teixeira (neck spasms) and Jacoby Ellsbury (sore hip), were able to muster 13 hits. Didi Gregorius had a three-run double, McCann went 3-for-5 with two RBIs, and even Chase Headley had an RBI single.

“All of a sudden, I think we’re swinging the bats like we’re capable of and we’re getting contributions up and down the lineup,” Girardi said. “Some big hits early in the game, some big hits late in the game. They did a nice job.”