Detroit twice overcame a one-run deficit before breaking a 3-3 tie with a three-run eighth that was finished off by Kelly's homer.
It was the final regular-season home game for the Tigers, who are battling the Texas Rangers for the second home-field berth in the American League playoffs. The teams went into Wednesday's action with the same record, but the Tigers have the tiebreak advantage after sweeping the season series with Texas.
Detroit began its three-run eighth with Ryan Raburn being hit by a pitch thrown by Kelvin Herrera.
Miguel Cabrera doubled home Raburn and then came out for pinch-runner Danny Worth, who scored in the inning on Kelly's sixth homer. Herrera (0-1) took the loss in his major league debut.
The win went to Doug Fister (10-13), who gave up an unearned run on two hits in three relief innings.
Martinez drove in his runs with a first-inning single, a fifth-inning groundout and a seventh-inning base hit that forged a 3-3 tie.