Timo Meier scored two goals for the Sharks, who won their third straight game, improved to 17-11-5 and moved into second place in the Pacific Division.
"This was a big win for us tonight," said Sharks coach Peter DeBoer. "We didn't start great, but you have to give them credit. I thought they played a very good game for back-to-back games. They were tight, and they didn't give us a lot of room."
After an uneventful first period, the pace picked up in the second and both teams scored once. The Stars struck first when a Julius Honka shot from the right circle hit the post, and Faksa put the rebound past Sharks goaltender Martin Jones to give Dallas a 1-0 lead at the 3:35 mark.
The Sharks drew even late in the period on a goal by Meier, who took a handoff from Brent Burns near the right point and then scored through a maze of players with a shot from about 50 feet to make it a 1-1 game at 16:30 of the second.
The Sharks broke the tie early in the third period on Meier's second goal of the game. Erik Karlsson knocked the puck away from Heiskanen as he entered the San Jose zone and the Sharks got a 3-on-1 going the other way that Meier finished off to make it a 2-1 game at the 2:50 mark. The Sharks extended the lead to 3-1 when San Jose defenseman Radim Simek's shot was blocked and the puck bounced right to Thornton, who put it into the open side of the net at 7:56 of the third.
The Stars cut the lead to 3-2 at the 12:24 mark when Jamie Benn set up Heiskanen in transition, and the Stars rookie defenseman scored on a shot from the slot for his seventh goal of the season.
The Stars pulled Khudobin for an extra attacker late in the game, had some good looks but couldn't get the puck to bounce their way and get the equalizer.