St. Louis took a one-run lead in both the seventh and eighth innings, only to have Detroit come back and tie it in the bottom half of the frames.
The Tigers finally struck quickly in the ninth off Kyle McClellan (0-3) to end a game that was delayed for almost 2 1/2 hours by rain in the fifth.
Thomas led off the ninth with a double to left on a 3-2 pitch and Sheffield also worked the count to 3-2 before delivering a single to center.
Skip Schumaker and Rick Ankiel started the offensive show by hitting solo homers in the first for St. Louis.
Carlos Guillen gave Detroit a 5-4 lead with a three-run homer in the fourth, but Ankiel hit his second blast of the game in the fifth to tie it just before the rains came.
The win went to Todd Jones (3-0), who worked a perfect top of the ninth. Detroit has won 13 of its last 17 games.