PITTSBURGH — For the second straight time against their hated rivals, the Flyers came back from the dead.

In the process, they saved their season — at least for now — with a stirring 2-1 overtime win over the Pittsburgh Penguins before a stunned sellout crowd Sunday night at PPG Paints Arena.

James van Riemsdyk scored in the closing seconds of regulation, and Sean Couturier deposited the winner with 3.4 seconds left in overtime as the Flyers avoided what would have been three straight losses for the first time in more than two months.

Carter Hart stopped 40 of 41 shots for the Flyers, who moved to within six points of a playoff spot with 10 games left.

“We’re definitely running out of time; it was a game we definitely needed the two points,” interim coach Scott Gordon said. “We got a lot of big performances at the end there.”

With Hart pulled for an extra attacker, van Riemsdyk tied it at 1-1with 18.8 seconds left as he converted a feed from Travis Konecny and one-timed a shot from the high slot past Matt Murray. It was the left winger’s 10th goal in the last 11 games.

The game was reminiscent of the Stadium Series contest at Lincoln Financial Field last month, when the Flyers scored twice with their goalie pulled, then won in OT against the Pens, 4-3.

“It just shows the character we have in this room with this group,” Hart said after the Flyers became the first team in NHL history to defeat the same team twice in a season when twice scoring the tying goal in the final 30 seconds of regulation.

In this OT, Hart made seven saves, including great stops on Sidney Crosby and Brian Dumoulin (rebound).

With 1 minute 15 seconds left in regulation and Hart pulled for an extra skater, defenseman Ivan Provorov made a diving play to knock the puck away from Nick Bjugstad as he was about to tap the puck in the empty net.

“He saved the game,” Gordon said.

So did Hart.

“He was unbelievable,” defenseman Shayne Gostisbehere said. “He’s something else right now.”

Teddy Blueger, inserted as the second-line center because of an injury to Evgeni Malkin, was left all alone and he scored on a rebound to give Pittsburgh a 1-0 lead with 17:53 left in regulation.

A short time later, fans began chanting “16,000,” referring to how many days it’s been since the Flyers last won the Stanley Cup. The number had been publicized in the local paper.

Hart was the only reason the Flyers still had a chance to steal a win heading into the final period. The rookie goaltender made 26 saves — including 18 in a Penguins-dominated second period — to keep the game scoreless after two periods.

Hart, 20, was rusty in Thursday’s 5-2 loss to Washington because it was the first game he had played in three weeks, having been sidelined by an ankle injury. Before being shelved, he had allowed three goals on nine shots in consecutive games and was pulled in losses to Tampa Bay and Montreal, respectively.

“We really took it to them in the third,” said Hart, whose team had 19 shots in that period after having a combined 13 in the first two periods. “That was the game plan. We didn’t fire a lot in the first two periods, and then we played our game and played hard and fired to the net — and eventually one was going to go in.”

Added Hart, who had his former junior-level head coach and goalie coach at the game and won for the first time since Feb. 17: “It was just very cool to be a part of that game. It’s hard to describe. A lot of emotions and it was just a lot of fun.”

The Flyers won three of the four games against the Penguins this season. A year ago, Pittsburgh eliminated the Flyers in the opening round of the playoffs, 4-2.

Claude Giroux was fighting flu-like symptoms and was unable to participate in Sunday’s morning skate. but the Flyers’ captain was in the lineup.

Giroux (plus-2, six shots, all after the second period), who was used sparingly in the first period but got more time as the game progressed, appeared to give the Flyers a 1-0 lead and break the team’s 0-for-14 power-play drought with 18:49 to go in the second.

But the officials on the ice said his shot went past Murray only because Jake Voracek interfered with the goalie. The Flyers challenged and won. The goal counted. For about a minute. The Penguins then challenged that Voracek was offside at the beginning of the sequence. Again, the Situation Room in Toronto reversed the on-ice decision. No goal.

So it was still scoreless, and it remained that way because Hart denied Bjugstad on a breakaway with 14:31 to go in the second, then made a two terrific stops on close-range shots by Patric Hornqvist about a half-minute later.