Erik Cole cleaned up a puck in front to give Montreal its third lead of the game, 3-2, at 8:46 of the third period.
But Clowe scored on a rebound in the slot to tie it, and Pavelski beat Carey Price through the legs in the sixth round of the shootout to end San Jose's two-game losing streak.
"We were trying to lose it in the third when we gave up the goal, but I'm glad we stuck with it," said Sharks head coach Todd McLellan.
Montreal has lost six straight games in San Jose dating back to its last win on November 23, 1999.
On the go-ahead goal in the third period, Desharnais stole the puck from Joe Thornton behind the Sharks net and tried a wrap-around. Cole, standing to the right of Niemi, was there to hammer it in.
But Clowe was in the right place at the other end, slipping into the slot to corral the loose puck off Couture's shot and beating Price to make it 3-3.
"I kind of came in late," Clowe said, describing it as a set play. "I'm happy to see that go in. Sometimes in doesn't."
Before Pavelski, Martin Havlat and Michal Handzus also scored in the shootout for San Jose. The Canadiens got goals from Brian Gionta and Desharnais, who led all players with three points in regulation.
Montreal had leads of 1-0 and 2-1 after Cammalleri and Desharnais scored goals in the first and second period. But the Sharks came back both times, with McGinn and Couture tying the game.
The Sharks started a four-game homestand that also includes visits from the Panthers, Wild and Stars...Montreal went 0-for-1 on the power play and is 0- for-24 in its last six games. San Jose was also 0-for-1 on the power play...The Canadiens played the second game of a California road trip that started with a 4-1 loss in Anaheim on Wednesday and ends at Los Angeles on Saturday.