PHILADELPHIA (AP) -- With a playoff berth at stake, the New York Islanders pulled off a rally to remember.

New York Islanders' Anders Lee celebrates after scoring past Philadelphia Flyers goalie Steve Mason, left, with 28 seconds remaining in the third period (AP Photo/Tom Mihalek)

It's the finish to forget they have to shake off.

Brayden Schenn capped a wild final 2 minutes with the winning goal with 2.1 seconds left to lift the Philadelphia Flyers past the New York Islanders 5-4 on Tuesday night.

With a chance to wrap up a playoff berth, the Islanders wiped out a 4-1 deficit in the third period and nearly sent the game into overtime. Johnny Boychuk scored with 1:44 remaining in the game to make it 4-3 and Anders Lee, who scored earlier in the period to ignite the rally, tied it with 28 seconds to go.

The Islanders needed a win or a Pittsburgh win at Ottawa to clinch an Eastern Conference playoff berth. The Penguins, also chasing a playoff spot in the final days of the season, blew a 3-0 lead and lost 4-3 in overtime to the Senators. The Islanders play at Pittsburgh on Friday night.

"The puck has bounced crazy for us this year and there's nothing you can do about it," Islanders coach Jack Capuano said. "You have to put it behind and move forward."

Islanders goalie Jaroslav Halak took "full responsibility" for Schenn's goal and the loss.

"It went in, don't know what happened," he said. "Hit my stick, thought I had it inside of me. It was behind me. I don't know. I have to take a look at video at what really happened."

On fan appreciation night, the Flyers raffled off prizes, jerseys and sticks.

They nearly gave away the game.

"I thought it was going to overtime," Flyers goalie Steve Mason said. "That's why you play until the last second."

Claude Giroux scored two goals and Pierre-Edouard Bellemare and Carlo Colaiacovo also had goals.

Jakub Voracek had a pair of assists for the Flyers, keeping him in the hunt for his first career NHL scoring title. scored for the Flyers.

John Tavares took over the NHL scoring lead with a goal and two assists for the Islanders in their bid for one final run at a Stanley Cup from Uniondale, New York. They move to Brooklyn's Barclays Center next season.

The Islanders will play their final regular season game at Nassau Coliseum on Saturday. They'd like a few more home games in the playoffs.

"We've had a heck of a season at this point but we have to find a way and solidify," Tavares said.

Long out of the playoff hunt, the Flyers continued to play their best against teams in the hunt for the Cup. In 32 games since the All-Star break, the Flyers are 11-2-5 against playoff teams and just 3-5-6 against teams out of the race.

Giroux, an All-Star, had two quick goals in the first set up by Voracek and defenseman Mark Streit. Giroux's first was a one-timer on the power-play goal and his second came less than 5 minutes later to give Mason an early cushion. Giroux scored just his second even-strength goal at home of the season.

Streit, a former Islanders captain, hit the 50-point mark with three assists and became the first Flyers defenseman to reach that total since the retired Chris Pronger in 2009-10.

"We moved the puck well, we stayed patient, stuck with it and finally got the goal," Streit said. "The second goal ... we took advantage of an odd-man rush with good puck movement and it was a great shot by Giroux."

Giroux remained stuck on two goals and still has not yet scored a hat trick during the regular season. His lone three-goal game came against Pittsburgh in the 2012 playoffs.

Tavares scored his 36th goal of the season on the power-play in the second to make it 2-1. He entered just a point behind Pittsburgh's Sidney Crosby in the scoring race. Voracek was two points behind Crosby.

The Flyers stretched the lead on Bellemare's sixth goal of the season in the second and Colaiacovo's second of the season in the third.

The lead should have been enough to finish off the Islanders. Instead, Schenn did the trick with his 18th goal of the season.