NEW YORK (AP) — Ryan Pulock scored the tiebreaking goal with 41 seconds remaining and the New York Islanders recovered after giving up a three-goal lead to beat the Philadelphia Flyers 5-3 Tuesday night.

Josh Bailey, Jordan Eberle and Leo Komarov each had a goal and an assist, and Matt Martin also scored to help the Islanders win for the fifth time in eight games (5-1-2). Mathew Barzal had three assists.

Semyon Varlamov stopped 35 shots as New York beat its Metropolitan Division rival for the third time in three meetings this season. The Islanders, splitting home games between the Nassau Coliseum and Barclays Center, improved to 7-0-3 in Brooklyn.

Travis Konecny, Robert Hagg and Sean Couturier scored for the Flyers, who lost for just the fourth time in 12 games (8-3-1). Claude Giroux and Scott Laughton each had two assists, and Brian Elliott finished with 20 saves.

Couturier tied the score 3-all with 1:32 remaining from the left side on a carom off the end boards for his 16th of the season.

Pulock restored New York’s lead just 51 seconds later on a slap shot from straightaway for his seventh.

Komarov added an empty-netter in the closing seconds to seal the win.

Varlamov had 10 saves in the first period, 12 in the second and 13 in the third to win for just the second time in seven starts (2-4-1).

Varlamov gloved a shot by Philippe Myers on a rush at 5:44 of the second, preserving New York’s 3-0 lead and drawing chants of “Var-ly! Var-ly!’ from the crowd.

The Flyers then scored twice in 2:22 to get within one.

Konecny fired a shot from the left point that beat Varlamov for his team-leading 19th to pull Philadelphia to 3-1 at 9:34.

Hagg crashed the net and knocked in the rebound of Claude Giroux’s shot with just under eight minutes remaining in the middle period. It was the defenseman’s second of the season and first since Jan. 8 against Washington.

With the Islanders on the game’s first power play, Varlamov made a stellar stop on Michael Raffl’s short-handed try to preserve the lead with 3:42 left.

The Islanders scored three times in a 7:51 stretch of the first period to take the lead.

Bailey opened the scoring at 7:45 as he fired a one-timer off a pass from Barzal from the top of the left circle. The puck deflected off the stick of Philadelphia’s Tyler Pitlick and under the crossbar for Bailey’s 12th.

Martin made it 2-0 as he scored from the right side on a 2-on-1 rush with Leo Komarov with 8:47 left in the first. It was Martin’s fifth of the season and second in four games. Komarov got his 100th career assist on the play.

After some sustained pressure in the offensive zone, the Islanders added to their lead with 4:24 remaining in the opening period as Eberle knocked in the rebound of Barzal’s backhand for his 10th.

NOTES: Islanders C Casey Cizikas left early in the first period with an apparent knee injury following a collision with Philadelphia’s Ivan Provorov. Cizikas did not return. … Barzal has 110 assists and 76 points in 11 career games against the Flyers. … Eberle has five goals and two assists in 19 games against Philadelphia. … The Islanders won the first two meetings, 5-3 at Nassau Coliseum on Oct. 27, and 4-3 in a shootout at Philadelphia on Nov. 16. The teams conclude season series March 24 at Philadelphia. … Giroux has 37 assists and 55 points in 52 games against the Islanders.

UP NEXT

Flyers: At Florida on Thursday night and Tampa Bay on Saturday to finish a three-game trip.

Islanders: At Nashville on Thursday night to open a four-game trip.