ST. PETERSBURG, Fla. (AP) Salvador Perez gave the Royals a late lift Wednesday night heading into a key midseason series.
Perez hit a go-ahead, three-run homer in the ninth inning and Kansas City beat Tampa Bay 5-4 to take two of three from the Rays.
The second-place Royals return home Thursday night to begin a four-game series against AL Central-leading Detroit, which has a 4 1/2-game lead.
''That was a huge win for us,'' Kansas City manager Ned Yost said. ''That's the difference between 4 1/2 games back compared to 5 1/2 games back. Definitely nice to have a little momentum going home for the last four games before the All-Star break. It's a lot better than the alternative.''
Kirby Yates (0-1), the fifth Tampa Bay reliever, entered with runners at the corners and gave up Perez's one-out shot into the left-field corner.
Perez wasn't sure if the drive would stay fair or even clear the low fence near the foul pole.
''As soon as the ball hit on the other side, good for us,'' he said.
It's been a big week for Perez, chosen Sunday to start at catcher for the American League in next week's All-Star game.
Aaron Crow (4-1) pitched a scoreless eighth and Greg Holland got three outs for his 24th save.
All-Star outfielder Alex Gordon (sprained right wrist) and third baseman Mike Moustakas (flu) were not in Kansas City's starting lineup. In addition, left-hander Jason Vargas was taken to the hospital for an appendectomy.
Gordon entered as a ninth-inning defensive replacement. He will have an MRI exam Thursday.
''I don't think it's anything serious,'' he said.
Kevin Kiermaier went 4 for 4 with a grand slam for the Rays.
Tampa Bay, which lost for the fourth time in 14 games, missed a chance to gain a game on AL East-leading Baltimore. The Rays remained nine games back of the Orioles in fourth place.
''It stings a little bit,'' Yates said. ''It's a game we could have won and we needed to win. Obviously, it doesn't feel good. It's a situation where you let your team down, but there's nothing I can do about it now.''
After starter Yordano Ventura walked light-hitting Jose Molina to load the bases with two outs in the fourth, Kiermaier sent a shot into the right-field stands to give Tampa Bay a 4-2 lead.
Eric Hosmer hit a first-pitch solo homer with two outs in the first off Alex Cobb that put the Royals up 1-0. It was the first time Cobb pitched against Kansas City since being struck near the right ear June 15 last year by a liner hit by Hosmer.
Cobb, sidelined for two months due to problems that included a concussion and symptoms of vertigo, allowed two runs and six hits in 6 2-3 innings.
Ventura gave up four runs, five hits and four walks in five innings. He struck out five.
The Royals loaded the bases with no outs in the fourth, but scored just once to take a 2-0 lead on Raul Ibanez's grounder. Kansas City failed to score with the bases loaded and two outs in the seventh when reliever Grant Balfour got a pop fly from Perez.
NOTES: Kansas City is 2-37 when trailing entering the ninth inning. ... Tampa Bay SS Yunel Escobar (shoulder) could return Friday. ... Kansas City RHP Jeremy Guthrie (5-7) and Tigers LHP Drew Smyly (4-8) are Thursday's scheduled starters. ... The Rays are off Thursday before starting a three-game series Friday night against Toronto.