Sometimes the line between triumph and heartbreak can be so thin you can see right through it.

Or so it seemed on Wednesday night at the Prudential Center, when the Devils went from the brink of loss to the edge of victory, all the way there and then back again, just over the span of the final 20 minutes of regulation against the Canadiens.

Yet that black-hearted mistress known as the shootout was again the Devils’ foil, ending this one with a painstaking 4-3 win for Montreal, making the Devils winless in all of the five skills competitions they have entered this season.

“We went to four forwards for the last 30 seconds of overtime trying to avoid the shootout,” said coach Pete DeBoer, whose team took just one point from this home-and-home with the Canadiens, starting with a 3-2 loss in Montreal on Tuesday. “But that didn’t work.”

The only thing that has worked for the Devils (11-12-6) at all this season in the shootout came from this game’s first contestant, 20-year-old rookie Reid Boucher, making his NHL debut and getting the only goal the team has scored in 17 attempts this season. But it couldn’t hold up, as Cory Schneider allowed tallies to Lars Eller and David Desharnais, and the Devils’ goalie had his personal three-game winning streak come to an end.

“It’s hard to give your guys a chance to win if you don’t make a save,” said Schneider, who did make 27 stops, but just not the pivotal ones that could have won the game down the stretch. “I’m upset with myself.”

If Schneider is to blame for what happened in the third period, it was hard to tell because things happened with such ferocity it was almost a blur. The Canadiens (17-9-3) entered the period up 1-0, but as the Devils continued to push the play, their hard work finally was rewarded with goals from Andrei Loktionov and Michael Ryder within the period’s first 10 minutes, staking them to a 2-1 lead.

“It was good to see us battle and get some goals,” Schneider said about his squad that came in ranked 26th in the league in scoring. “But we pride ourselves on playing tight defense and making leads stand up, so we’re not too happy about that.”

Eller started the chaos with a little backhand that snuck through Schneider’s legs, tying it with just 3:50 to play. But with just 1:06 to go, it was Devils veteran Patrik Elias converting a bad defensive-zone turnover by Montreal’s All-Star defenseman P.K. Subban, giving the team what looked to be an insurmountable 3-2 lead.

“It still a lot of time, but you feel good about it, no question, especially the way we play,” Elias said. “We play tight. That goal is on us [who] were on the ice.”

That goal would be the one that went in with 37 seconds left in regulation, a high deflection off the stick of Desharnais, one that started with Elias blowing a tire in the corner and then a long point shot from former Devil Brian Gionta, finding its way behind Schneider and sending the game to overtime.

“Not bad,” Elias said about the team’s play, now 8-5-2 in its past 15 as the Devils prepare for this weekend’s back-to-back, starting Friday against visiting Detroit followed by a Garden match against the Rangers. “We could have got four points here in the last two games. It’s disappointing just getting one here, no question about it.”