With the game tied 2-2, Milan Michalek took possession behind the Dallas net and passed in front to Thornton, who beat Marty Turco for his 12th of the season.
Patrick Marleau added a goal, Jonathan Cheechoo scored on the power play and Evgeni Nabokov stopped 17 shots for the Sharks, who improved to 7-1-3 in their last 11 games and pulled within two points of the first-place Stars in the Pacific Division.
U.S.-born goal-scoring leader Mike Modano notched the 516th of his career, and defenceman Trevor Daley added his first of the season for the Stars, opening a four-game homestand after going 4-2 on an East Coast trip.
Turco made 25 saves for the Stars, who had won eight of their previous 10.
Dallas held a two-man advantage for 47 seconds with less than three minutes left, but San Jose limited the Stars' scoring chances and ended Dallas' four-game home winning streak.
Cheechoo got the game's first goal at 18:15 of the opening period, notching his fourth when he banked the puck off the stick of Dallas defenceman Nicklas Grossman and past Turco while Stars defenceman Mattias Norstrom was in the penalty box for holding.
Cheechoo has been slumping this season after scoring 37 goals in 2006-07.
Daley got the Stars even at 1-1 at 3:31 of the second period, taking the puck the length of the ice and beating Nabokov from the right circle.
Marleau put the Sharks back in front 2-1 with his fifth of the season at 6:02 of the second period, striking from the slot off Thornton's setup.
But Modano tied it 2-2 on a sharp-angle shot at 6:08 of the third period, his ninth of the season.
Notes: Marleau has five goals in the last two seasons against the Stars. ... San Jose scratches included LW Ryane Clowe (knee), D Brad Norton (back) and C Marcel Goc (back). ... Earlier in the day, the Stars announced that D Philippe Boucher will go on IR and miss at least four weeks because of shoulder surgery. Boucher has been playing through the injury that coach Dave Tippett described as "normal wear and tear," and Boucher stayed in the lineup until Norstrom was healthy enough to be activated earlier this week. Norstrom has recovered from a facial injury and played for the first time since Nov. 7. ... RW Junior Lessard was recalled from Dallas AHL affiliate in Iowa to replace Boucher. Lessard had eight goals and 10 assists in 21 games for the Iowa Stars this season.