NEW YORK — Riley Nash scored both goals Saturday night for the Boston Bruins, who moved into sole possession of the second wild card in the Eastern Conference with a 2-1 victory over the New York Islanders at Barclays Center.

The win snapped a four-game losing streak for the Bruins (39-30-6), who broke a tie with the Islanders for the final wild card. New York has a game in hand on Boston.

Nash scored just beyond the midway point of the first period and recorded the game-winner 4:12 into the third period.

Just as with his first goal, Nash’s second score was set up by Dominic Moore, who won a battle for the puck with Adam Pelech near center ice. Moore passed to Nash, who beat Islanders goalie Thomas Greiss from the left faceoff circle.

Goaltender Anton Khudobin, playing in place of injured starter Tuukka Rask, recorded 18 saves.

John Tavares scored for the Islanders (35-27-12), who generated the tie for the second wild card by beating a pair of Eastern Conference contenders, the New York Rangers and Pittsburgh Penguins, in their previous two games. Tavares nearly tied the game on a power play late in the third, but his shot bounced off the crossbar.

Greiss made 16 saves.

The teams traded goals during a wild 36-second span in the first period.

Tavares opened the scoring with a nifty individual effort in which he corralled the puck at the Islanders’ blue line, skated up the right side of the ice and weaved his way past Bruins defenseman Kevan Miller, who tried to jab the puck free with his hand. Tavares fired a shot under the legs of Boston defenseman Adam McQuaid and past Khudobin’s stick at 10:05.

The goal was just being announced over the public address system when the Bruins tied it on Nash’s unassisted goal. Moore descended upon Islanders defenseman Scott Mayfield and poked the puck free. Nash picked it up, raced toward Greiss and faked a pass to Moore before firing a shot under Greiss’ stick.

The Bruins appeared to take the lead a little more than five minutes later when Frank Vatrano fired a rebound past Greiss. But Greiss was brought down moments earlier by Boston right winger David Backes and Islanders coach Doug Weight challenged the play. Officials overturned the goal after a brief review.

The negated goal served to rein in both teams, who combined for 15 shots during the second period.

NOTES: The Islanders scratched D Johnny Boychuk (lower body), LW Nikolay Kulemin (lower body) and RW Ryan Strome (broken wrist) as well as G Jean-Francois Berube, D Thomas Hickey and C Alan Quine. … In addition to G Tuukka Rask, the Bruins scratched LW Matt Beleskey (family leave) and C Tim Schaller (lower body) as well as D John-Michael Liles and D Joe Morrow. To replace Rask, the Bruins recalled G Zane McIntyre from Providence of the AHL on an emergency basis. … The Islanders were denied their first sweep of the Bruins since 2005-06.