Mariano Rivera got a hero’s welcome on enemy turf last night and made his final All-Star appearance a Sandman Special.

Summoned in the eighth inning of the 84th All-Star game because manager Jim Leyland wanted to ensure Rivera would get to pitch, the Yankees icon was perfect — and named the Most Valuable Player of the AL’s 3-0 domination of the NL before 45,186, the largest crowd in Citi Field history.

“As a team player you don’t look for these things, they just happen,” said Rivera, who became the first Yankees player since Derek Jeter in 2000 to win the All-Star game MVP award. “I’m honored and proud to be a member of the New York Yankees and being able to play for this city and to do it the way I have done.”

Rivera, who is set to retire after the season, entered to a standing ovation and waved his cap to the crowd upon reaching the mound. To let Rivera bask in the moment, his AL teammates delayed in taking their positions, leaving the future Hall of Fame closer alone during the 60-second ovation.

“It felt so weird — basically I was there alone with my catcher,” Rivera said. “I definitely appreciated what they did for me.”

Then, Rivera retired the side in order and departed to more applause.

Leyland said it would have been too risky waiting until the ninth to let Rivera pitch. If the NL rallied and took the lead in the eighth, there might not have been a bottom of the ninth.

“You know, I’m probably not the most popular manager in baseball,” Leyland said. “I wanted to make sure I got out of here alive tonight.”

Rivera’s AL teammates also seemed moved by the events.

“I had goose bumps the whole time,” Dustin Pedroia said. “It was nice not to worry about facing him.”

The performance came on a night the NL All-Stars were limited to three hits, one of which came from David Wright, who singled in the seventh. The victory, which carries home-field advantage for the World Series, was the AL’s first since 2009.

Robinson Cano might have suggested “This time, it hurts” as the official game slogan, after Matt Harvey drilled him in the right leg in the first inning. It stood as the snapshot moment — until Rivera’s appearance in the eighth — of the first Midsummer Classic hosted by the Mets since 1964.

Cano, the only Yankees starter, departed with a contusion to his right quadriceps shortly after getting plunked and was long a spectator by the time Joe Nathan threw the final pitch in the ninth.

Harvey, the first Mets pitcher to start an All-Star game since Dwight Gooden in 1988, pitched two shutout innings. Wright finished 1-for-3 with a single in the seventh inning against Greg Holland, but also left a runner stranded at third in the fourth.

Mike Trout had just opened the game with a double, when Harvey drilled Cano in the right leg with a 96-mph missile. Cano remained in the game as Miguel Cabrera struck out, but then walked off the field, replaced by Pedroia. Cano underwent precautionary X-rays, which were negative.

“That was the last thing I wanted to do was go out there and possibly injure somebody,” Harvey said. “As [Cano] was walking by I was trying to get his attention as he was going to first. When he came off, obviously I apologized and made sure that he was OK.”

Cano said there were no hard feelings.

“I know he doesn’t want to hit anybody,” Cano said. “But it’s just part of the game, so what else can you do?”