Montreal is in fourth place in the seven-team Scotia North Division, six points ahead of Calgary, which has played three more games. The top four teams in the division will qualify for the Stanley Cup Playoffs.
"We know these games against Montreal are so crucial," Calgary forward Mikael Backlund said. "So it feels really, really sour to lose today, and it's just really disappointing, a tough loss."
Toffoli deflected Joel Armia's pass into the top right corner for his second goal of the game, his Canadiens-leading 21st, to put Montreal up 2-1 at 15:45 of the third period.
It was Armia's first point in two games after missing eight because of the NHL COVID-19 protocol.
"He's been at home in isolation, and it's tough on a guy, especially dealing with that and not being around the guys," Canadiens captain Shea Weber said. "So to be back and contributing, I'm sure he's thrilled."
Toffoli scored his 20th goal on a wrist shot past Markstrom's glove from the slot to give Montreal a 1-0 lead at 9:32 of the second period.
It is Toffoli's fifth 20-goal season in the NHL, and his fastest (38 games). He scored his 20th goal in his 42nd game with the Los Angeles Kings in 2015-16.