Tyler Toffoli tied it for Montreal at 6:11 of the third period, with Gallagher assisting on the play. Toffoli then helped set up Gallagher's winner.
''Find a way,'' Gallagher said about the message in the second intermission. ''Our goaltender gave us the biggest opportunity to go out there and win that hockey game. We were able to come out and outplay them for 20 minutes.
''That's kind of what this league is. You've got to take advantage of those opportunities when you get them. We've been on the other side where you outplay teams and let them hang around.''
Tomas Tatar, Montreal's scoring leader last season, was a healthy scratch.
Mitch Marner scored early in the first period for Toronto, and Frederik Andersen stopped 23 shots.
''We didn't make good on the chances that we earned in the first,'' Toronto coach Sheldon Keefe said. ''We had more than enough offence there in the first to blow this game wide open and didn't capitalize. Then our game was a mess from there.''
Auston Matthews had an assist for Toronto to extend his points streak to 11. The Maple Leafs lost in regulation for the first time since Jan. 20. Toronto fell to 11-3-1 and saw its lead atop the North Division shrink to three points over the Canadiens.
''They just kept competing hard,'' Maple Leafs captain John Tavares said. ''They were physical. We just weren't able to be as in sync as we'd like to be and find that other level to our game.''
Montreal opened the season 7-1-2, but entered Saturday having lost three of its last four in regulation - all at home - including a 4-2 loss to Toronto on Wednesday night and a 3-0 setback to Edmonton the following night.
''We just gutted it out,'' Canadiens captain Shea Weber said. ''Everyone stepped up.''
Canadiens: Host Toronto on Saturday, May 20.
Maple Leafs: Host Ottawa Monday, Wednesday and Thursday nights.
Copyright 2021 STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.