Benn Ferriero broke a third-period tie with 11:12 left, and Anti Niemi stopped 37 shots for the Sharks, who have won consecutive games for the first time this season.
Milan Lucic scored for Boston, then assisted on Tyler Seguin's game-tying goal just 29 seconds later as the Bruins rallied to tie it in the third period. But Ferriero, a Boston native who played at Boston College and in the minors in nearby Worcester, slammed in a rebound for the game-winner.
Patrick Marleau scored an empty-netter with 4.8 seconds left.
Reigning Vezina and Conn Smythe Trophy winner Tim Thomas made 26 saves for the Bruins, who are 2-4 at home as they attempt to defend their NHL title. They have scored four goals total in the four losses.
Boston picked Thornton No. 1 overall in the 1997 draft, but shipped him away after eight seasons amid complaints that he wasn't tough enough to lead the Bruins to a championship. It took another six years, but the Bruins finally won the Stanley Cup in 2011, and that seemed to make both sides forget the somewhat acrimonious way he was shipped out of town.
During a first-period commercial break, the Bruins played a video tribute to Thornton to congratulate him on playing his 1,000th NHL game a night earlier in New Jersey. He waved to the crowd as it gave him a nice ovation, and both benches banged their sticks in his honor.
It didn't take long for Thornton to reintroduce himself.
The game was just 72 seconds old when Joe Pavelski collected a loose puck at the blue line, skated in and snapped a wrist shot past Thomas' glove. San Jose scored again in the second period when Martin Havlat dug out a puck behind the net and passed it to Logan Couture in the slot to make it 2-0.
Boston finally scored with 17:17 left in the game when the puck bounced through the crease, near the goal line and behind Niemi's back. It made it to Lucic on the other side and he swatted it in to make it 2-1.
Just 29 seconds later, Seguin worked a give-and-go with Lucic to tie it.
But Vandermeer helped set up Ferriero for the go-ahead goal in the third, and Niemi made it hold up.
Notes: Bruins defenseman Adam McQuaid missed his fourth straight game with headaches and neck pain. ... The Sharks beat the Devils on Friday night in a shootout. Joe Thornton had a goal and an assist, and Pavelski tied it with 33 seconds left in regulation. ... Seguin skated gingerly over to the bench in the final three minutes and didn't return. ... The Sharks have won four straight in Boston.