The Maple Leafs took a 1-0 lead at 3:36 of the first period when Marner took a pass in the slot from Auston Matthews, who stole the puck from Canadiens forward Phillip Danault behind the net.
The assist the extended Matthews' point streak to nine games (12 points; nine goals, three assists). The forward, who did not play against the Edmonton Oilers on Jan. 22, has a point in his past 12 games played (16 points; 11 goals, five assists).
Maple Leafs forwards Alex Kerfoot and William Nylander hit the post five seconds apart late in the first period.
"We weren't good in the first two periods that's for sure, we know that," Montreal captain Shea Weber said. "Carey kept us in it and stood on his head and gave us a chance to be ourselves in the third."
Toffoli tied it 1-1 from low in the left face-off circle at 6:11 of the third after a pass from Danault, who got the puck after Gallagher collected it off the right boards following a dump-in.
"We were so fortunate that we were only down one," Gallagher said. "That's what gave us life, we knew we were one shot away and how that can change momentum. Toffoli scoring that goal was huge for us. Massive goal and a great play by Phillip, and then we're right back in that game."
Montreal outshot Toronto 12-6 in the third period.
"They came in with a sense of urgency with the way the last few games have gone for them," Maple Leafs captain John Tavares said. "They played hard, just tried to play physical. Obviously, we're aware of some of the things that we do well. That's part of it, we've seen it throughout the season so far. We have to find a way to break through."
The Canadiens do not play again until next Saturday, when they host the Maple Leafs.
"There absolutely was urgency for us," Julien said. "Let's not kid ourselves, if we'd come out with another loss, that's four losses in five games and then a week to sit on that, it makes a huge difference. This win here is one of those wins you need at the right time of the schedule. This was huge for us. It puts our mindset in a much better position."
NOTES:Canadiens forward Tomas Tatar was a healthy scratch. He played in each of the previous 14 games this season. ... Matthews' point streak is the longest active in the NHL and tied for second-longest of the season with Johnny Gaudreau of the Calgary Flames and Brad Marchand of the Boston Bruins. Connor McDavid and Leon Draisaitl of the Edmonton Oilers each had a 10-game point streak from Jan. 20-Feb. 8.