The Buffalo Sabres haven’t had much to celebrate. When they finally earned the chance, they forgot how.

At the close of a chaotic 5-4 shootout win over Montreal on Thursday, the Sabres’ victory party was in disarray. A few players jubilantly hopped into the dressing room. Others exchanged high-fives in the hallway. A handful remained on the ice soaking in the applause of the faithful.

Captain Jason Pominville finally managed to get them on the same page. In various stages of dress, from full uniform to lower pads only, the Sabres skated back to center ice and raised their sticks to the fans.

It was a welcome moment for both sides.

The Sabres avoided their fourth straight loss with a last-second goal by Thomas Vanek, then earned their second victory in nine games when Vanek and Pominville scored in the shootout. The Sabres also snapped a three-game winless skid in First Niagara Center. It was cause for celebration, no matter how awkward.

“I just think we forgot about it because we hadn’t won at home for a while,” said goaltender Ryan Miller, who stopped two of three Montreal attempts in the shootout. “It was a little bit clunky, like the game, but eventually we all got out there.”

There was little reason to believe they would win. The boos were raining down on the Sabres harder than they had all season. The team was seconds away from seeing another loss added to their 1-6-1 slide.

The fans who stuck around in the crowd of 18,866 quickly changed their tune.

With Miller pulled for an extra attacker, the Sabres got the puck near the Montreal net after several failed attempts. Once it got close, Vanek did the rest.

The NHL’s most potent player, while on his knees at the side of the body-filled crease, pushed and poked at goalie Peter Budaj and the puck. Both finally slid over the goal line with 1.9 seconds left as the fans erupted and Vanek’s teammates mobbed him.

“We found a way to get it in,” Vanek said. “It was a feeling that we finally got a point that we needed. That was a good feeling.”

Because of the hole they created with their slide, they don’t get to celebrate long. Having already nullified a stirring win over Boston with a debacle in Montreal this season, the Sabres are eager to try for two wins in a row Saturday when they visit the New York Islanders.

“It really is about winning the next game already, about putting this one behind us and focusing on getting better and getting on a run because we’ve got some ground to make up,” coach Lindy Ruff said.

The third-period rally from a two-goal deficit eased Buffalo’s continuing troubles with team defense. The Sabres allowed at least four goals for the sixth straight game. It’s the first time that has happened under Ruff, who began coaching the team in 1997.

“I don’t think I’ve ever been through a stretch where we’ve made as many poor decisions or mistakes, whatever you want to call them, that have led to some great opportunities by the other team,” Ruff said.

Buffalo allowed the Canadiens to build leads of 1-0, 2-1, 3-2 and 4-2. The Sabres answered every time.

Steve Ott needed just 15 seconds to erase Montreal’s opening goal. Tyler Ennis scored 35 seconds after the Habs made it 2-1.

Buffalo’s ultimate comeback started when it finally connected on the power play. After opening the game 0 for 5, including a two-man advantage, Vanek scored on the power play with 12:03 left to make it 4-3. The goal ended a 0-for-17 drought and gave them four goals in 35 chances since the opener.

“We had a lot of chances, myself included, in the second,” Vanek said. “I could have had two or three, and I just thought to myself, ‘You know, maybe it’s one of those nights, but just keep going.’

“At the end I got rewarded and as a team we got two points that we really needed.”

They needed the postgame party, too.

“It was definitely an awkward celebration for the fans,” left wing Marcus Foligno said, “but it was good to have everyone out there and salute them for the tough stretch that we went through.”