BOSTON -- Danton Heinen scored his first NHL hat trick in the Boston Bruins’ 9-4 win against the Montreal Canadiens at TD Garden on Saturday.

The Bruins led 5-4 entering the third period before scoring four straight goals, with Heinen’s third goal of the night capping it off.

“Some games you feel like you play well, and you help the team and stuff like that, and it may not go in,” Heinen said. “Other nights you may not feel like you have it and sometimes it goes in, so I think that was maybe one of those nights tonight, but yeah, I just try to help the team, so it’s nice to help on the scoreboard too.”

David Pastrnak scored his 30th goal of the season and had an assist, and Linus Ullmark made 17 saves in his return from a lower-body injury for Boston (28-8-9), which extended its winning streak to four and point streak to eight games (5-0-3).

Sixteen players had a point for Boston.

“I think it talks about the evolution of our team actually growing offensively,” Bruins coach Jim Montgomery said. “I don’t think we ever envisioned having a night like this. Over the course of 82 games, there’s some outliers, but I thought that we’ve been seeing this coming here for four games.”

Cole Caufield scored in his fifth straight game, and Sean Monahan had three assists for Montreal (19-20-7), which has lost five of seven (2-3-2). Sam Montembeault made 22 saves in 49:13; Cayden Primeau made five saves in relief.

“I thought through two periods it was a great game,” Canadiens coach Martin St. Louis said. “It was fun getting to be part of it. Third period was hard. Every now and then, this League will humble you. That’s kind of what happened to the team in the third period.”

Caufield gave the Canadiens a 1-0 lead at 9:18 of the first period with a power-play goal from the right side of the net.

Brandon Carlo, who missed the previous five games with an upper-body injury, tied it 1-1 at 12:47, redirecting Trent Frederic’s centering pass.

Joel Armia gave Montreal a 2-1 lead at 15:00 on Joshua Roy’s centering pass off the rush.

Jake DeBrusk tied it 2-2 at 18:10 from the side of the net, and Heinen redirected Matt Grzelcyk’s shot pass to put the Bruins ahead 3-2 at 19:05.

Mike Matheson tied it 3-3 from the high slot on the power play at 6:16 of the second period.

“If we could take one positive from it, it would probably be [scoring two power-play goals],” Matheson said. “They’re a great penalty kill, so I think we did a good job of not worrying too much about where you’re supposed to be, quote unquote, depending on where your position is and really just supporting each other.”

MTL@BOS: Coyle, Pastrnak team up for a goal in 2nd

Heinen gave the Bruins a 4-3 lead at 10:46 off the rush.

Pastrnak fed Charlie Coyle for a backhand tip-in just 49 seconds later to make it 5-3.

“I’m still figuring out [linemates Pastrnak’s and Brad Marchand’s] tendencies,” Coyle said. “I mean, they’re world-class players, so just trying to create space and play my game. I’m not trying to overthink it. I’m just trying to play the way I know how and figure it out slowly along the way.”

Brendan Gallagher cut it to 5-4 at 13:19, poking it through Ullmark’s legs.

Pastrnak made it 6-4 at 1:26 of the third period, following up his own shot on a breakaway, and Coyle fed Marchand in the slot to make it 7-4 at 4:32.

“We knew that was how we were going to win this year,” Marchand said. “Obviously ‘Pasta’s’ an exception, he produces every night, but we win by committee here, and that’s how you need to win in the playoffs.”

MTL@BOS: Pastrnak scores his 30th goal of the season

Pavel Zacha made it 8-4 at 9:13 on the doorstep for his 100th NHL goal, and Heinen scored a power-play goal at 10:40 for the 9-4 final.

“Maybe on our breakouts, we did a lot of turnovers,” said Montembault, who was replaced by Primeau after Zacha’s goal. “We know this team always comes out on the forecheck. We should have just kept it simple. We talked [entering] the third, we should have just kept fighting. We were just one goal away, but it felt like maybe we gave up a little bit, and they came back and scored a couple goals after.”

NOTES: Caufield became the fifth Canadiens player in the past 50 years to have a five-game goal streak at age 23 or younger, following Andrei Kostitsyn (five games in 2008-09), John LeClair (five in 1992-93), Steve Shutt (five in 1974-75) and Guy Lafleur (five in 1974-75). … Marchand secured his 11th consecutive 20-goal season and passed Patrice Bergeron (10) and Johnny Bucyk (10) for the most in Bruins history. … Pastrnak reached the 30-goal mark for the seventh time, matching Bucyk for the second-most in Bruins history behind Phil Esposito (8) and Rick Middleton (8). Pastrnak also surpassed Petr Klima (6) for the second most 30-goal seasons by a Czechia-born player in NHL history, behind Jaromir Jagr (15).