Jorge Soler, Hunter Dozier and Carlos Santana homered for Kansas City, which trailed 6-3 heading to the bottom of the seventh inning. Scott Barlow (1-0) allowed Joey Wendle's tiebreaking RBI double in the ninth, but got the win when the Royals rallied.
Michael A. Taylor sparked the game-ending rally with a leadoff single for Kansas City. Jarrod Dyson came in to run, swiped second and advanced to third on Hanser Alberto's sacrifice bunt against Diego Castillio (0-1).
Dyson then slid home safely on Nicky Lopez's safety squeeze, tying it at 8. After Lopez advanced on a groundout, Santana was intentionally walked before Perez lined a 2-1 pitch up the third-base line for the winning hit.
''Dyson has just been huge for this team in so many ways,'' Royals manager Mike Matheny said. ''Getting him to third by Hanser and then Nicky doing his job. Once again, it's the Salvy show.''
The Royals have won 54 straight when leading after seven innings, the longest active streak in baseball.
''I just tried to do my job,'' Perez said. ''He is a great closer and has been good so just try to see something up and hit it hard. He left a slider up and I got it pretty good.''
Perez hit a game-ending homer to give Kansas City a 3-2 victory over Toronto in the second game of a doubleheader on Saturday. The veteran catcher slugged a two-run shot in the seventh inning of the Royals' 2-0 win against the Blue Jays on Sunday.
Wendle had two hits and three RBIs for Tampa Bay, which had won five in a row. Brandon Lowe hit a two-run homer during the Rays' four-run first inning against Jakob Junis.
''I've seen some really good clubs check out after being down four in the first,'' Matheny said. ''I just think our DNA in this clubhouse is belief. It was a team effort if I've ever seen one.''
Tampa Bay right-hander Michael Wacha permitted three runs and five hits in 5 2/3 innings.
''I thought he threw the ball well,'' Rays manager Kevin Cash said. ''He competed well and gave us a chance. The home-run ball got him.''
Austin Meadows' RBI double gave the Rays a 6-3 lead in the seventh. But the Royals responded with four runs in the bottom half.
Alberto hit a two-run triple, and Santana connected for a two-run drive with two out.
Royals: RHP Jesse Hahn (right shoulder impingement syndrome) is eligible to return from the 10-day injured list Thursday.
Rays: Open a 10-game homestand on Friday with a matchup with Toronto, with Tyler Glasnow (2-0, 0.73 ERA) on the mound for Tampa Bay.
Royals: Begin a nine-game road trip Friday in Detroit. Mike Minor (1-1, 5.17 ERA) pitches for Kansas City.
Copyright 2021 STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.