Tyler Toffoli's goal in the second period was the winner. Toffoli scored his fourth goal in as many games and his team-leading 25th of the season.
Montreal opened a six-point gap on Calgary, which is chasing the Canadiens for the fourth and final playoff berth in the North Division.
Shea Weber also scored for the Canadiens. Jake Allen made 21 saves for the win.
''It's a big road win against a team we need to win against, but there's still a lot left to do and some tough games coming up,'' Weber said.
Elias Lindholm scored for Calgary. Jacob Markstrom had 22 saves in the loss.
''A frustrating loss for sure,'' Markstrom said. ''It's such small coincidences, small margins from being really successful.
''I feel like we've been on the wrong side of that way too many times this season. It starts with me in close games to keep us in the game and make that extra save.''
The Flames beat Montreal in back-to-back games to start the three-games-in-four-days series.
Montreal has a game in hand on Calgary. The Canadiens' schedule down the stretch is tough with seven of their last nine games against teams ranked higher in the division.
Three of Calgary's last eight are versus higher-ranked clubs. The Flames finish with four straight games against the Vancouver Canucks.
Calgary took the nine-game season series against the Canadiens 6-3, but losing the finale means the Flames will likely need to win out and hope the Habs lose a lot of games to end their season.
''We'd be lying if we're saying we're not gonna be watching what's going on around us, but if we don't win our games, it's really not going to matter anyway, so we've got to pile up some wins,'' Flames captain Mark Giordano said.
The Flames didn't score on a man advantage to start the third period, nor did they on another power play at the midway point. Both teams scored once on three power-play chances.
Calgary captain Mark Giordano's shot went off the inside post, but the puck stayed out early in the third.
Montreal led 2-1 on Toffoli's goal at 18:05 of the second period.
Joel Armia took the rebound on Toffoli's initial shot to send it back for Toffoli to score on a second attempt, while Markstrom was tangled with teammate Chris Tanev.
''I'd be lying if I would say there's no puck luck or bounces going my way certain nights, but it's just been a fun ride,'' Toffoli said.
Calgary drew even 1-1 at with a power-play goal at 12:17 of the first period. Lindholm gathered Johnny Gaudreau's pass through the slot and beat Allen with a wrist shot from a sharp angle.
With Calgary's Derek Ryan and Mark Giordano serving minors, Montreal scored a 5-on-3 goal at 9:59. Weber put a rising slap shot over Markstrom's glove.
NOTES: Canadiens right-winger Cole Caulfield made his NHL debut Monday. Montreal drafted him in the first round (15th overall) in 2019. Caulfield won this year's Hobey Baker Award as the top player in men's NCAA hockey. ... The Flames announced before the game that defenseman Noah Hanifin is out for the season with a shoulder injury requiring surgery. Nikita Nesterov moved into the lineup. ... Lindholm has six goals and four assists in his last 10 games. ... Gaudreau has two goals and four assists in five games. ... Montreal forwards Jonathan Drouin (non-COVID illness) and Paul Byron (lower-body injury) were scratched a second straight game. ... Calgary forward Josh Leivo remained on the NHL's COVID protocol list.
Canadiens: Host the Toronto Maple Leafs on Wednesday.
Flames: At Edmonton on Thursday for the first of a two-game set.
More AP NHL: https://apnews.com/hub/NHL and https://twitter.com/AP-Sports
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.