The Rays (8-8) trailed 7-5 after six innings but rallied for a run in the seventh and then got to closer Francisco Rodriguez in the ninth.
Kevin Kiermaier walked and Evan Longoria doubled to right field, and the Tigers intentionally walked Brad Miller to load the bases with no outs.
With one out, Logan Morrison hit what looked to be a double-play ball to second, but shortstop Jose Iglesias stumbled as he tagged the base and threw wide, allowing two runs to score on the throwing error for the win.
Miller slid into Iglesias as he fell on the base paths, and he was down for a moment after the game before walking off the field on his own.
Two outfield miscues had allowed five runs to score as the Rays turned a 5-1 lead into a 7-5 deficit in two innings. Even Kiermaier, the Rays' two-time Gold Glove center fielder, missed a line drive with two outs and the bases loaded in the sixth, so instead of a 5-4 lead and the inning over, the Rays trailed 7-5 after three runs scored on Nicholas Castellanos' second triple of the night.
Tampa Bay's bullpen made it harder in the sixth -- Danny Farquhar issued a four-pitch walk, then hit Andrew Romine with his next pitch. A double play helped negate that, but reliever Jumbo Diaz walked the next two batters to load the bases and set up Kiermaier's uncharacteristic mistake in the field.
An inning earlier, a line drive popped out of the glove of left fielder Shane Peterson as he hit the ground on a diving catch, allowing two runs to score on a ball hit by Victor Martinez.
Detroit starter Jordan Zimmermann gave up 10 hits and five earned runs but still was in line for the win, despite two would-be outs dropping in right field in part due to poor communication and trouble spotting the ball against the stadium's white roof.
Justin Wilson struck out the side for Detroit in the eighth.
The Rays pulled within a run in the seventh, getting three singles off reliever Alex Wilson -- Steven Souza's single brought in Kiermaier and put the tying run in scoring position with one out, but the Rays couldn't tie it up.
The Rays jumped out to a 5-1 lead for starter Chris Archer, but fielding woes contributed to a three-run fifth for Detroit to pull within a run.
Iglesias singled out of the No. 9 hole to lead off the fifth, with Ian Kinsler walking and Miguel Cabrera coming through with a one-out RBI double to cut the lead to 5-2.
Martinez sent a line drive to left field and Peterson, playing the outfield for the first time at Tropicana Field, dived to make the catch. But the ball popped out of his glove, allowing two runs to score on what was ruled a single to make it 5-4.
Detroit had outfield miscues of its own -- Corey Dickerson led off the first with a pop to right-center field, where neither JaCoby Jones nor Tyler Collins called for the ball and both watched it drop between them for a double.
Kiermaier dropped a perfect bunt single down the third-base line, and Longoria hit an RBI infield single for a 1-0 lead. Steven Souza followed with a one-out RBI single to make it 2-0 early against Zimmermann.
Detroit got back within a run in the third as Cabrera singled to bring in Kinsler, but the Rays got three in the fourth to extend their lead. Peterson doubled and scored on Dickerson's RBI single, and after a Kiermaier double, Longoria ripped a two-run single to left to make it 5-1.
Archer pitched well, striking out nine but lasting only five innings, throwing 104 pitches. He had held Detroit to four hits through four innings but gave up three hits and three runs in the fifth.
NOTES: Tigers OF Justin Upton was out of the lineup, one day after he bruised his right wrist making contact with Rays SS Tim Beckham as he slid into second. He's not expected to play in Thursday's series finale, but no word was given on his return beyond that. ... Detroit's record of 13 straight games with a home run, the longest in baseball since the Indians in 2002, came to an end. ... With Jake Odorizzi on the disabled list with a hamstring injury, the Rays will throw a bullpen day on Thursday, with reliever Erasmo Ramirez getting the start. It's his first start in more than a year, and he was stretched out with a four-inning, 46-pitch outing Saturday in a loss at Boston.