Perez put the Royals ahead with a two-run blast in the first inning estimated at 418 feet, and he tied the game at 4 leading off the sixth. It was the fourth multi-homer game this season and 10th of his career for Perez, who marked the 10th anniversary of his major league debut.
"Tonight was amazing, especially because we won the game," Perez said. "That's the most important thing.
"The 10 years have gone quickly. It was a dream come true to play in the big leagues. Hopefully I can stay here and play for another 10 years."
A night earlier, the Royals became the first team since 1900 to erase a deficit in the seventh, eighth, ninth and 10th innings before falling to New York in 11. This time, Kansas City pushed ahead and stayed there following Perez's tying homer off Nestor Cortes (0-1). Later in the sixth, Hunter Dozier doubled against Stephen Ridings to score Emmanuel Rivera from first.
"Obviously Salvy (Perez) got (Cortes) a couple of times for big blows," Yankees manager Aaron Boone said. "We had some mistakes in the strike zone and they made us pay. Overall, we didn't play our best tonight."
The Royals played small ball to extend their lead. Michael A. Taylor led off the seventh with a double. Hanser Alberto put down a sacrifice bunt, and Taylor scored on a throwing error by Ridings. Alberto scored on a safety squeeze by Nicky Lopez.
Alberto added a sacrifice fly in the eighth.
"We went about it a little differently. It was a lot of the things we talk so much about, the situational hitting. It's a shame the game doesn't appreciate those plays as much as it should," Royals manager Mike Matheny said. "I thought today was one of our better ballgames all the way around, being the type of team the Kansas City Royals are."
Reliever Josh Staumont (2-2) retired all four batters he faced, striking out three, one of five Kansas City pitchers who held New York to five hits.
Kyle Higashioka hit a two-run homer for the Yankees, who have lost two of three following a five-game winning streak. New York is trying to chase down Tampa Bay and slumping Boston in the AL East and Boston and Oakland in the wild-card race.
Higashioka's homer put New York ahead 3-2 in the fourth, but the Royals tied it in the fifth when Whit Merrifield scored on catcher Higashioka's throwing error.
D.J. LeMahieu's RBI single gave the Yankees a 4-3 lead in the sixth.
OF Edward Olivares was the victim of the Royals using seven relievers Monday night as he was optioned to Triple-A Omaha to make room for RHP Joel Payamps, who was recalled.
The Yankees have not announced a starter for the final game of the series on Wednesday. New York has won 11 consecutive series against the Royals, who will start right-hander Brady Singer (3-7, 5.13 ERA).
Perez tattoos Yankees for 2 homers
Salvador Perez hits two home runs against Nestor Cortes Jr. as the Royals prevail vs. the Yankees.