Martin St. Louis scored a pair of goals, winner with 32.8 seconds left in overtime, as the Tampa Bay 5.
Dwayne Roloson made 45 saves for the victors.
"There's a lot of time left in this season and you never know what can happen," said St. Louis. "If we throw in the towel because of what's going on around us, it's going to be a pretty miserable last two months."
Tommy Wingels and Logan Couture each had a goal and an assist for the Sharks, who acquired forward Dominic Moore and a seventh-round selection in the 2012 NHL Entry Draft from the Lightning in exchange for a second-round selection, previously acquired from Minnesota, in 2012 prior to the game.
"He has to be better, flat out has to be better," said San Jose head coach Todd McLellan about Niemi. "They scored four goals on net play, rebounds, picking up the garbage, wraparounds, jams. That's our defensemen. That's our low forwards. So everybody has some responsibility, but (Niemi) knows he has to be better."
Down 4-3, Stamkos tied the game on a snap shot from the slot at the 2:44 mark of the third period.
St. Louis gave the home team a 5-4 lead at the 8:01 mark. His shot from the side of the net hit off a San Jose defender and trickled past Niemi.
But Wingels tied the game with just 5:10 to play. Couture gathered a loose puck at center ice and led a 2-on-1 rush into the offensive zone. Wingels accepted a cross-ice pass and beat Roloson with a snap shot.
The Lightning claimed victory with time winding down in overtime. Victor Hedman carried the puck below the goal line and started to make his way around the net. He made a perfect centering pass to St. Louis, who chipped the puck into the back of the net.
Couture opened the scoring with a power-play goal just 1:16 into the game. But Stamkos lit the lamp at 9:30 and Purcell scored a power-play goal with 25 seconds left to give the Lightning a 2-1 lead.
San Jose dominated the middle stanza, outshooting the Lightning by a 20-4 margin. Handzus made it a 2-2 game at the 1:44 mark, but Downie put the home team back in front at 14:08.
Vlasic tied the game just 29 seconds later and White made it a 4-3 contest with 4:16 left.
The Sharks had won two in a row against the Lightning...San Jose is now 1-1-1 on a nine-game road trip that continues Friday night at Carolina...Tampa Bay held defenseman Pavel Kubina out of the lineup, as the team is looking to trade him...Lightning defenseman Matt Gilroy (upper body) was back in the lineup after missing two games.