Thornton, who is earning $7.2 million this season, was slated to become an unrestricted free agent July 1 and would have been arguably the biggest name on the market.
"Joe stepped up and made a tremendous commitment to this franchise, his teammates and the fans in San Jose," Sharks general manager Doug Wilson said. "We are very pleased that we now have another key piece of this team's core under contract for the next four seasons."
The 31-year-old center has been among the league's scoring leaders for the better part of his career, winning the Hart Trophy as NHL MVP in 2005-06 and helping Canada capture Olympic gold at the Vancouver Games.
He was second in the NHL last season with 69 assists.
Pierre LeBrun covers the NHL for ESPN.com.