Ross Colton scored twice, and Andrei Vasilevskiy made 27 saves for Tampa Bay (46-22-8), which lead the Boston Bruins by one point for third place in the Atlantic Division.
Jakub Vrana scored twice, and Thomas Greiss made 38 saves for the Red Wings (30-37-10), who had been outscored 10-1 in their previous two games.
After Colton tied it 3-3 on a one-timer 43 seconds into the third period, Vrana forced a turnover by Mikhail Sergachev at the blue line and beat Vasilevskiy on a breakaway to put Detroit back in front 4-3 at 5:09.
"He played as complete a hockey game as he's played all year for us," Red Wings coach Jeff Blashill said. "I thought he was excellent in every facet of the game. He checked great, he worked hard, he won battles, he was good on the wall.
"I think that's a little personified by the breakaway goal. He does a good job defensively and then goes down and scores."
Colton gave the Lightning a 1-0 lead at 3:58 of the second period. Stamkos received a touch pass by Ondrej Palat, split the defense, and passed back to Colton in the left circle for a shot into an open net.
Oskar Sundqvist tied it 1-1 at 4:20 with a backhand five-hole in front after Danny DeKeyser's shot produced a rebound.
Vrana gave the Red Wings a 2-1 lead at 6:34 with a shot from the right circle.
"I'm trying to create offense here as much as possible to give the team a chance," Vrana said. "There are things that we have to do to get those chances, and that's what we did tonight. We put ourselves in a good position to win the game."