Verlander (19-5) allowed one run on three hits and three walks while fanning eight in the right-hander's seventh consecutive victory. He also tied his career-high in wins with his major league-leading 19th victory.
Jeff Niemann (8-5) gave up four runs on six hits and three walks in 7 1/3 innings. He had won his previous seven decisions prior to the loss, his first since May 4 against Toronto.
Joyce's leadoff home run into the bleachers in right-center field in the bottom of the first inning gave the Rays an early 1-0 lead.
But it was short-lived, as Avila answered with a two-run shot to left in the second. Miguel Cabrera led off the frame with a soft liner into center field prior to Avila's opposite-field homer.
After a single by Brennan Boesch and a double by Delmon Young put runners on second and third with one out in the eighth inning, Niemann intentionally walked Cabrera to load the bases before being replaced by Jake McGee.
McGee struck out Avila looking on a fastball at the knees before he was pulled in favor of Juan Cruz. But Jhonny Peralta greeted Cruz with a single through the left side of the infield to score Boesch and Young, increasing the Tigers' lead to 4-1.
Kelly's leadoff homer in the ninth pushed it to 5-1.
Longoria led off the ninth with a bomb over the left-field fence off Jose Valverde. A Casey Kotchman base hit and a Sam Fuld walk later brought the game-tying run the plate with two outs, but John Jaso bounced a weak grounder to second to end the game.
After Joyce's homer, Verlander did not let another runner touch second base until Johnny Damon legged out a one-out double in the sixth. Verlander would strand him there, though, by inducing a Longoria grounder to third and fanning Ben Zobrist on three pitches.