Melendez, who went 3-for-4 with two RBIs, a run, a walk and two stolen bases, chopped a ball near first that Yandy Diaz failed to flip to pitcher Pete Fairbanks (0-2) covering first base. That plated Maikel Garcia, who led off with a walk and then stole his second and third bases of the game.
Drew Waters went 2-for-4 with a solo homer, three RBIs and a stolen base. Garcia added two hits, two runs and an RBI. Dairon Blanco tripled and scored for the Royals, who stole seven bags
Opener Jose Cuas made his first start in 80 career appearances and allowed two runs in 1 1/3 innings.
Aroldis Chapman (3-2), the Royals' sixth pitcher, earned the win by striking out the side in the eighth. Scott Barlow notched his ninth save
Tampa Bay's Randy Arozarena went 3-for-5 with three RBIs, and Diaz finished with three hits and two runs.
Seeking his major-league-leading 12th win, Rays starter Shane McClanahan instead was removed in the top of the fourth after a tense exchange with manager Kevin Cash and the game tied at 2
McClanahan, who threw a season-low 66 pitches over 3 2/3 innings, gave up two runs on four hits while fanning three and walking two.
The Rays later announced that McClanahan left with mid-back tightness
Diaz singled to lead off the first, went to second when Luke Raley was hit by Cuas, and scored on Arozarena's single. Isaac Paredes' sacrifice fly then brought in Raley.
In the third, the Royals managed to tie it after Blanco's leadoff triple to left and Garcia's single. After a walk pushed Garcia to second, Melendez singled him home
Waters launched his second homer of the season narrowly inside the right-field foul pole for a brief lead in the seventh, but Francisco Mejia matched it in the bottom half with his third of the season.
The Rays were without star shortstop Wander Franco, who was benched for at least the first two games of the series due to his failure to handle his failures in a professional manner, according to manager Kevin Cash
--Field Level Media