UNIONDALE, N.Y. — Kevan Miller scored the go-ahead goal late in the second period, Tuukka Rask stopped 43 shots, and the Boston Bruins beat the New York Islanders 5-2 Thursday night.

Reilly Smith, Patrice Bergeron, Torey Krug and Zdeno Chara also scored for Boston, which won for the seventh time in 10 games. Smith and Milan Lucic also had two assists each.

John Tavares and Michael Grabner scored for New York, while Jaroslav Halak stopped 28 shots. It was the Metropolitan Division-leading Islanders’ fifth loss in 22 games (17-5-0) at home this season.

Miller put the Bruins ahead for good with 3.4 seconds left in the second. He intercepted Halak’s clearing attempt at the right wing boards just inside the blue line, and fired a quick shot that found the back of the net to give Boston a 3-2 lead.

Krug’s goal 1:45 into the third essentially decided a game that had seen wild momentum shifts. Chara added an empty-netter with 2:06 left.

Smith opened the scoring with 6:01 left in the first period by driving to the net and redirecting Milan Lucic’s feed past Halak. Bergeron pushed the lead to 2-0 with a power-play goal 2:10 later.

Rask tried to make the lead stand. The Boston goaltender’s toughest stop was a diving save on Michael Grabner’s goalmouth backhand 5:34 into the second. The Boston goalie was also the beneficiary of some good fortune as Brock Nelson had a wide open net 46 seconds later, but his shot hit the post.

However, a misplay by Rask let the Islanders back into the game.

Rask couldn’t control Tavares’ dump-in from the neutral zone, and the New York captain lifted a backhander into the net 8:25 into the second to cut the deficit to 2-1. The goal was Tavares’ 23rd of the season and his fourth in four games.

Grabner drew the Islanders even with 4:48 left in the second with his fifth of the season, setting the stage for Miller’s tiebreaking score.

Boston evened the season series against New York at 1-1. New York won the first game, 3-2 on Oct. 23 in Boston. The teams will end the season series Feb. 7 at Boston.