Carey Price stopped 20 shots to improve to 5-1 in his last six starts, a stretch in which he's allowed just 10 goals. For Gallagher, the goal came in his first game after missing six straight and 10 of 11 with headaches and concussion-related issues.
Tomas Tatar sealed Montreal's fifth win in seven games with an empty-net goal with 1:47 left.
Jack Eichel scored for Buffalo, becoming the team's first player in 27 years to reach 30 goals in 50 or fewer games.
Carter Hutton made 27 saves in a loss that extended his skid to 12 games. He's gone 0-8-4 in his past 13 appearances since opening the season with six wins.
The Sabres turned to Hutton with starter Linus Ullmark expected to miss between three and four weeks after hurting his right leg in a 5-2 loss to Ottawa on Tuesday.
Hutton was making his second start in six weeks, and first since allowing five goals on 34 shots in a 6-3 loss to Vancouver on Jan. 11.
The game's momentum switched midway through the first period, and with Buffalo up 1-0 and having a 9-0 edge in shots. The Canadiens then took control in the opening minutes of the second period and eventually outshot Buffalo 30-21.
Kovalchuk scored 44 seconds in with a shot from in close, and after Buffalo defenseman Jake McCabe ran into Montreal forward Nick Suzuki.
A major defensive breakdown led to Gallagher's go-ahead goal.
Four Sabres defenders shaded toward Tatar in the right corner, where he spun around and made a no-look pass through the middle to find Gallagher all alone at the left post. Gallagher made a few moves to draw Hutton out of position before backhanding a shot in behind the goalie.
''We just weren't managing the puck all that well,'' Gallagher said of the Canadiens' slow start.
''We just played smarter, we played better hockey, and that's what you've got to do,'' he added, crediting Price for keeping the deficit to just one goal. ''We felt fortunate the game was right there for us to come take, and that's what we did.''
Buffalo dropped to 0-2 since coming out of a week off, and in the midst of what was supposed to be a crucial stretch for a team playing nine of 10 at home.
Sabres fans, already upset with Buffalo's dud Tuesday against Ottawa, proceeded to boo the team off the ice following the second period.
Confidence - or lack thereof - was the problem, McCabe said.
''I think our start in the second wasn't ideal, and we kind of went into a shell and none of us were playing with confidence the rest of the game,'' he explained.
McCabe was reminded of how the Sabres have endured familiar late-season collapses during an eight-year playoff drought that stands as the NHL's longest active streak.
''To be honest with you, tune you guys out, tune the negativity out, because I know we've got a lot of good guys in here and a group that's really focused,'' McCabe said.
Eichel opened the scoring 7:11 in, and 22 seconds after Montreal's Joel Armia was penalized for tripping. Rasmus Dahlin set him up in the left circle, where Eichel beat Price on the short side.
With 34 assists, Eichel became the first Sabres player to reach 30 goals and 30 assists since Jason Pominville had 30 and 43 in 2011-12. Eichel also became the first Sabres player to score 30 in his first 50 games of a season since Pat LaFontaine (42 games) and Alexander Mogilny (47) both did it in 1992-93.
NOTES: Sabres RW Kyle Okposo played just 3:47 of the first period and did not return after sustaining what coach Ralph Krueger called an upper-body injury but not one involving Okposo's head in ruling out the possibility of a concussion for a player who has a history of them. Krueger added he doesn't expect Okposo to play against Columbus on Saturday. ... The game was Gallagher's 530th with Montreal, moving him into a tie with Claude Larose for 52nd on the franchise list. ... Canadiens D Marco Scandella returned to Buffalo for the first time since being traded to Montreal three weeks ago.
Canadiens: Host the Florida Panthers on Saturday.
Sabres: Host the Blue Jackets on Saturday.
More AP NHL: https://apnews.com/NHL and https://twitter.com/AP-Sports
Copyright 2020 by STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.