The Islanders are going in the wrong direction at the worst possible time. They have gotten lost on the road to the playoffs.

After claiming only one point while losing the previous four games, the Isles faced off with Montreal on Friday night at Barclays Center to close a home-and-home set.

They began four points back for the second wild card with two other teams in between. They also are about to go on the road for the next four games. So the Islanders really couldn’t afford to throw away two more points at home against a team that’s all but out of the race.

They did it anyway. Alex Galchenyuk scored a hat trick and set up a fourth goal and the Canadiens broke open a tie game with three goals in the third period on the way to a 6-3 win.

Indeed, the Islanders scored in the final six seconds of two different periods for the first time in their 3,565 regular-season games, rallied to tie after falling behind by a goal three times and still lost. Now they’re at 29-29-7 with 17 games left.

“It’s tough,” Josh Bailey said. “We all want to win. We all want to be in the postseason. It’s going to take a lot of work from here on out, obviously. It’s going to be difficult. But we’re certainly not going to throw in the towel.”

Subscribe to Newsday’s sports newsletter

Receive stories, photos and videos about your favorite New York teams plus national sports news and events.

The Islanders are four points behind Carolina and Columbus, which are tied for the final wild-card spot, and three points behind Florida.

Montreal, which began play 11 points behind in the race for the second wild card, beat the Isles, 3-1, on Wednesday night.

This time Paul Byron broke a 3-3 tie with a shot from the slot at 8:10 of the third after Jaroslav Halak deflected a wraparound attempt. Noah Juulsen scored his first NHL goal 1:43 later. And Galchenyuk added an empty-netter with 49 seconds left.

“We felt like we’d get our chances along the way,” Canadiens coach Claude Julien said. “If you do your homework, they’re one of the teams that have given up the most goals.”

Galchenyuk put Montreal ahead 2-1 just 2:17 into the second, beating Halak on a rebound. Then Nick Leddy sent in Bailey, who beat Charlie Lindgren at 4:23 to tie it. It was his career-high-tying 16th goal.

But Leddy provided an assist to Montreal on the next goal. The defenseman turned the puck over in his own zone, sending it right to Mike Reilly, who whipped a pass to Galchenyuk in the right circle. His blast beat Halak at 10:31, and it was a 3-2 game.

The Islanders received a power play late in the second, and Anthony Beauvillier sent the puck from the right circle to Brock Nelson in front. His redirection got past Lindgren to tie it with 3.3 seconds on the clock (Tanner Fritz had tied it at 1-1 with 5.8 seconds left in the first).

“It’s the same as the last three or four games,” Thomas Hickey said. “Those are chances to get at least one, probably two points every single time. And to come up with zero, it’s unacceptable . . . We’re just digging a hole.”

This was the front end of a back-to-back. The Islanders will try again Saturday in Pittsburgh, with AHL call-up Christopher Gibson getting his first NHL start of the season in goal.

“We just have not been able to generate some momentum consistently, just execute at a high level,” John Tavares said. “We’ve had some bad third periods . . . We always seem to come out on the wrong side of it.”