TORONTO -- Auston Matthews scored a hat trick, including his 300th NHL goal, helping the Toronto Maple Leafs to a 6-5 shootout win against the Montreal Canadiens at Scotiabank Arena on Wednesday.

“It was a bit of a roller coaster,” Matthews said. “I think it’s obviously nice to get the win and there’s a lot of things we can definitely clean up, just taking care of the puck, some turnover stuff, little awareness type of stuff we can definitely be better at. It’s easy to say it’s the first game, but it’s those habits you try to build early on in camp that you just want to clean up early.”

William Nylander had a goal and an assist, John Tavares had three assists, and Ilya Samsonov made 19 saves for the Maple Leafs in the season opener for both teams. Mitchell Marner scored the only goal in the shootout.

Ehen asked what he would take from the game, Toronto coach Sheldon Keefe said, “Two points, that’s about it.

“You do [have to win ugly] for sure. So that’s my takeaway. The game presented almost everything you can think of in a game. It’s all over the place, which you don’t love to see.”

Alex Newhook scored twice in his Canadiens debut, and Jake Allen made 37 saves.

“We were definitely emotionally challenged, and to me, that’s a big part of this league,” Montreal coach Martin St. Louis said. “Emotionally challenged in the second, emotionally challenged at the end of the third, but you learn for it. There’s nothing you can do. It’s done, let’s go.”

MTL@TOR: Matthews scores his first three goals of season

The Maple Leafs cut it to 5-4 at 15:28 of the third period when Matthews took a pass from Tavares and shot to the short side from the bottom of the right face-off circle.

With Samsonov pulled for the extra attacker, Matthews then tied it 5-5 at 18:53 when he received a pass from Nylander and shot past an outstretched Allen for goal No. 302.

Newhook, who was acquired from the Colorado Avalanche in a trade June 27, had put the Canadiens up 4-3 at 5:47 of the third when he deflected an Arber Xhekaj shot in the slot for his second goal.

Jesse Ylonen made it 5-3 at 11:55, backhanding a shot past Samsonov’s blocker after a pass from Rafael Harvey-Pinard, who intercepted a clearing attempt from Timothy Liljegren.

“We lost some life for sure, it was tough,” Keefe said. “… It was definitely a tough one, especially the nature of the way some of the goals were happening. You just feel like it’s not your night. I don’t know how many times we fell down or whiffed on the puck.”

Matthews’ power-play goal tied it 2-2 at 14:51 of the second period. Marner’s shot ricocheted off Tavares in front of the net and came to Matthews, who shot from the bottom of the right circle. The goal made him the fastest United States-born player to reach 300 goals (482 games), passing Pat LaFontaine (549 games).

Nylander put Toronto up 3-2 on the power play at 19:15 of the second period when he one-timed a shot from John Klingberg at the left face-off dot. Klingberg was making his Maple Leafs debut after signing a one-year, $4.15 million contract as an unrestricted free agent July 1.

Cole Caufield tied it 3-3 with a power-play goal at 4:25 of the third when his shot from the slot deflected off the stick of Maple Leafs defenseman TJ Brodie. Caufield (shoulder surgery) played his first regular-season game since Jan. 19.

MTL@TOR: Caufield ties game with PPG in 3rd

Toronto outshot Montreal 16-2 in the second period.

Jake Evans put the Canadiens up 1-0 at 3:01 of the first period when he scored on a breakaway after Brodie mishandled the puck and fell at the offensive blue line.

Newhook made it 2-0 at 1:10 of the second, scoring at the side of the crease off a pass from Juraj Slafkovsky. Slafkovsky was playing his first game since Jan. 15, when a lower-body injury ended his rookie season.

“Not fun game for the goalies, especially for the Toronto goalies,” Samsonov said. “… I try to forget about what’s going on, sometimes we have these games, it’s not too fun but it’s OK. We win, we have two points, so I’m so excited about the results.”

Caufield had a goal overturned at 5:50 when Toronto challenged for offside.

“We’re a young team, and [these are] some good learning lessons to go through on how to manage the highs and lows of the game,” Canadiens forward Kirby Dach said. “… You’re going up 3-0 and the goal gets called back, and we don’t know how to push back or answer after that. There’s emotional swings in the game, and we have to find ways to just keep moving forward and rolling the way we were rolling. We kind of took our foot off the gas pedal.”

The Maple Leafs cut it to 2-1 at 7:46 when Noah Gregor shot past Allen’s glove from the left face-off dot. It was Gregor’s Toronto debut; he signed a one-year, $775 000 contract after attending training camp on a professional tryout.

NOTES: Matthews became the fifth player to score 300 goals with the Maple Leafs, joining Mats Sundin (420), Darryl Sittler (389), Dave Keon (365), and Ron Ellis (332). ... Matthews has 12 goals in season openers, passing Babe Dye (nine) for the most in Toronto history. ... Maple Leafs forward David Kampf played in his 400th NHL game, finishing with one shot on goal in 13:08. ... Toronto forward Fraser Minten, a second-round pick (No. 38) in the 2022 NHL Draft, made his NHL debut. He played 11:32, had one shot on goal and was minus-1. … Newhook became the eighth player to score multiple goals in his Canadiens debut.