TORONTO -- Auston Matthews scored with 40 seconds left in overtime to give the Toronto Maple Leafs a 2-1 win against the Buffalo Sabres at Scotiabank Arena on Wednesday.

Matthews shot blocker side from the slot after taking a pass from Mitch Marner, who was behind the net, for his NHL-leading 54th goal of the season.

“I just tried to find a quiet area there and Mitch made a really nice play obviously losing his guy a little bit,” Matthews said. “I just kind of got in between the two guys in front of the net and he made a beautiful pass to me, and I just tried to sneak it around the defenseman and by the goalie as soon as possible and I was lucky for it to go in.”

William Nylander scored, and Ilya Samsonov made 24 saves for the Maple Leafs (36-18-8), who are 10-2-0 in their past 12. The Maple Leafs lost 9-3 to the Sabres the last time they met, on Dec. 21.

“We weren’t great tonight and didn’t move the puck very well, and as a result didn’t generate much and when we did have opportunities to generate," Toronto coach Sheldon Keefe said. "I thought we overcooked it a little bit, tried to overpass and didn’t shoot enough. But the last time we played these guys, we gave up nine, so you can understand why the guys were a little gun-shy tonight and being a little more careful.”

Victor Olofsson scored, and Ukko-Pekka Luukkonen made 25 saves for the Sabres (29-29-5), who are 5-2-1 in their past eight.

“Yeah, I mean, obviously, they have some very highly skilled players over there, some of the best in the world,"  Buffalo forward Dylan Cozens said, "so we had to manage the puck and try not to give them much because they'll capitalize off those opportunities. We just wanted to play a mature game.”

Samsonov, who has won eight of his past nine starts, kept it 1-1 with a glove save on Tage Thompson at 3:38 of overtime.

“He’s been a rockstar for us,” Maple Leafs forward Tyler Bertuzzi said. “It’s good to see him do his thing again and have his confidence. He’s going to be awesome for us down the stretch.”

Buffalo did not have a shot on goal until Kyle Okposo was stopped at 14:50 of the first period but wound up outshooting Toronto 10-6 after 20 minutes.

“It was not fun but I’m just doing my work,” Samsonov said. “If I have nothing to do, I control what I can control and just try to do my best.”

Nylander put the Maple Leafs up 1-0 at 2:29 of the second period when he took a pass from Bertuzzi, who was behind the net, and shot from the slot.

“That was a beautiful pass, he found me there all alone in the slot so that was a nice connection there,” Nylander said.

“They did a pretty good job. I thought we were a little too cute, could have maybe attacked the net more (throughout the game), but we won, so ...”

Olofsson tied it 1-1 at 6:31 when he shot over Samsonov’s glove from the left face-off dot.

Olofsson was a projected healthy scratch until the Sabres traded forward Casey Mittelstadt to the Colorado Avalanche on Wednesday, opening a spot in the lineup. He had been a healthy scratch the previous nine games.

“I thought it was nice to get him in the lineup because he works hard,” Buffalo coach Don Granato said. “He is an absolute great person and a worker, and I talked to him before the game and I said, ‘Let’s communicate. I don’t want to put you in a bad spot, let’s see how you feel.’ And he looked at me with 100 percent confidence and said, ‘I’m ready to go.’ And, obviously, he was. That was a very big goal and very nice to see him persevere and cash in.”

Matthews said the Maple Leafs were focused on making sure they put forth a better effort than in the 9-3 loss to Buffalo.

“It was not too much of a topic of conversation but obviously something you keep in the back of your mind because the last time we played them, it got out of hand and [was] probably one of our worst outings of the year,” Matthews said. “You can’t change the past, just have to put our best foot forward and with another opportunity against them tonight, it’s nice to get the extra point there. They played hard, they played tight defensively and there wasn’t a whole lot there on either side. These are the kinds of games we need to be comfortable in.”

NOTES: Maple Leafs defenseman Jake McCabe did not play due to illness. Keefe did not confirm whether he would be available when Toronto faces the Boston Bruins on Thursday. ... Maple Leafs forward Noah Gregor played 9:02, was minus-1 and had two shots in his first game after missing six as a healthy scratch.