Gustafsson scored the decisive goal with 3 minutes, 36 seconds remaining. Jake Voracek added an empty-netter.
Taking a pass from Giroux, Gustafsson skated deep in Montreal's end and sent a puck on goal that bounced off a Canadiens defenseman and went in. It was Gustafsson's first goal of the season.
"I got it from [Giroux] and was looking to shoot it first, but the guy came out in my shooting lane so I faked it and put it in front," Gustafsson said. ". . . You never know what will happen, and it went in on a lucky bounce."
The Flyers had gotten the equalizer on Wayne Simmonds' 12th goal with 5:06 left. Bruno Gervais' shot bounced off Simmonds' skate.
With 12 games left, the Flyers are four points out of the eighth and final Eastern Conference playoff spot. The New York Rangers, New Jersey Devils, and New York Islanders are each tied for seventh with 39 points.
This was the end of a five-game homestand for the Flyers, who went 3-1-1 (3-0-1 after an opening loss) and play in Toronto on Thursday night in the first stop on a three-game trip.
Injuries continue to plague the Flyers. Zac Rinaldo did not return after he suffered a lower-body injury in the second period.
Montreal opened the scoring on defenseman Alexei Emelin's snap shot from inside the blue line with 6:47 left in the first period. Emelin received an outstanding back pass from Max Pacioretty for the only goal of the opening period.
The Flyers tied the score on a fluke goal by Sean Couturier, whose pass from inside the left circle went off the leg of P.K. Subban and into the net with 15:13 left in the second period.
"I got a nice pass in the slot from [Ruslan Fedotenko] and saw a chance to put the puck on the net and got a lucky bounce off a skate," Couturier said. "And I will take it."
The Flyers took a brief, 2-1 lead when Simon Gagne scored on a rebound off the boards with 4:17 remaining. Luke Schenn and Oliver Lauridsen got the assists. For Lauridsen, it was his first NHL point.
Montreal took the lead by scoring twice in 20 seconds. Brandon Prust got the equalizer on a wrist shot after a nice feed from Jeff Halpern with 3:31 left in the period.
David DeSharnais broke the tie, scoring from close range on a feed from Emelin with 3:11 remaining.
The Flyers came roaring back in the third period.
Contact Marc Narducci at firstname.lastname@example.org. Follow on Twitter @sjnard.