Updated

Thomas Vanek is off to a prolific start. And this time, the Sabres forward finally got a win to go with his production.

Vanek scored twice Thursday night, including jamming in the tying goal during a scramble in front with 2 seconds left in regulation. Then he came through in the shootout as Buffalo overcame a two-goal, third-period deficit to pull out a 5-4 win over the Montreal Canadiens.

Vanek upped his NHL-leading total to 21 points (10 goals, 11 assists). More important, he played an integral role in ending the Sabres' three-game skid and delivering their second win in nine games (2-6-1).

"It's great," Vanek said. "It means we get to not go home all frustrated tonight. Enjoy the win. Probably going to sleep better. Wake up tomorrow and go for the next one."

It was an uplifting win for a high-priced Sabres team that's lacked consistency and identity, and spent part of the game Thursday being booed for the second straight time at home. The first came on Sunday, when the Sabres squandered a two-goal lead in a 4-3 loss to Florida.

"We knew we had to keep grinding away at it," coach Lindy Ruff said. "We were finding ways to lose, and we found a way to win."

Jason Pominville also scored in the shootout and Ryan Miller clinched the victory by making a left pad save to stop Brian Gionta on Montreal's final opportunity. Tyler Ennis had a goal and two assists, while Steve Ott had a goal and an assist for Buffalo.

Tomas Plekanec scored twice for Montreal (6-3-1), which has dropped two straight — including a 2-1 loss to Boston on Wednesday. P.K. Subban and Brendan Gallagher also scored for the Canadiens.

Backup goalie Peter Budaj stopped 36 shots in his second start of the season.

"It's tough," Budaj said. "When you score four goals on the road you pretty much should win. I thought we did enough good things. We made a few mistakes and got punished for it. It's a tough way to go, especially when you're up two goals."

Budaj and the Canadiens appeared to be headed for a regulation victory after spending much of the final minute denying the Sabres a chance to even gain the Montreal zone. That changed with about 10 seconds left, when Marcus Foligno drove up the right wing, skated behind the net and flipped the puck into the crease.

Ennis got two whacks at the puck only to be stopped by Budaj. With a tangle of bodies lying in the crease, it was Vanek who dived in and somehow managed to poke the puck through the goalie's legs with 1.9 seconds showing on the clock.

Referee Tim Peel, parked behind the net, immediately ruled it a goal, which was confirmed after a video review.

Budaj wondered whether Peel could have blown the play dead a split-second earlier.

"The big question is whether the referee saw the puck," Budaj said. "I'm not blaming the referees or anything. It happened in a split-second and it was a matter of opinion."

Vanek never lost sight of the puck and dived into the pile of bodies hoping he could get a piece of it.

"I was patient. Once I saw it there, I just jumped at it and got a good whack at it," said Vanek, who knew time was running out. "I saw that black little thing and jumped on it. If the buzzer went, so be it."

The goals came late in a game in which Vanek thought he had squandered several scoring chances in the second period.

"I thought to myself that maybe it was one of those nights where it wasn't going to go in," Vanek said. "But I said, 'Stick with it.' As a team we stuck with it and we got rewarded."

The Canadiens appeared to take control when Plekanec scored on a breakaway 45 seconds into the third period to make it 4-2.

Subban made it 3-2 by one-timing a shot from the left circle with 1:28 left in the second. It came during a two-man advantage after Cody Hodgson (hooking) and Ott (high-sticking) were penalized 33 seconds apart.

Subban extended his point streak to four games (two goals, two assists), all coming since making his season debut in a 6-1 win over Buffalo last weekend after signing a two-year, $5.75 million contract.

NOTES: The Sabres went 1 of 7 on the power play and squandered their own two-man advantage that spanned 46 seconds early in the second period. ... Canadiens LW Travis Moen missed his first game of the season because of a lower-body injury sustained Wednesday. ... Montreal has scored a power-play goal in nine of 10 games. ... The Sabres are 117-101-37 against Montreal, their most wins against any opponent.