Toronto Maple Leafs right wing Connor Brown (12) and Boston Bruins defenseman Torey Krug (47) vie for the puck along the boards during the first period of an NHL hockey game in Boston, Saturday, Feb. 4, 2017. (AP Photo/Mary Schwalm)
Toronto Maple Leafs right wing Connor Brown (12) and Boston Bruins defenseman Torey Krug (47) vie for the puck along the boards during the first period of an NHL hockey game in Boston, Saturday, Feb. 4, 2017. (AP Photo/Mary Schwalm)

Boston— William Nylander got his first career hat trick, former University of New Hampshire standout James van Riemsdyk scored his second of the game to break a tie with 1:36 left and the Toronto Maple Leafs snapped a three-game losing streak with a 6-5 win over the Boston Bruins on Saturday night.

Connor Brown also scored for Toronto, which moved one point behind Boston for third place in the Atlantic Division. The Maple Leafs have played five fewer games than the Bruins.

David Pastrnak scored two goals for Boston, and Ryan Spooner, Patrice Bergeron and Torey Krug each added one. Bergeron and Krug had power-play goals.

Frederik Andersen stopped 36 shots for the Maple Leafs.

Goaltender Tuukka Rask, playing his 12th consecutive game, was pulled after the Maple Leafs’ fourth goal. Zane McIntyre made 10 saves in relief.

The Maple Leafs led 4-1 after getting three goals less than two minutes apart in the second period, but the Bruins charged back to tie it on Spooner’s goal with 9:54 left in the third.

Brown banged home a shot from the slot to put Toronto back ahead, but Bergeron tied it again with 2:54 to play.

Van Riemsdyk scored from the right point, beating a screened McIntyre.

One of the loudest cheers of the night came when highlights of each of the Patriots’ four Super Bowl victories was played on the Jumbotron — the biggest roar came on the clip of Malcolm Butler intercepting a pass at the goal line in 2015.

Seconds later, Toronto moved ahead 2-1 when Adam McQuaid’s bad clearing pass caromed off the boards and ended up with van Riemsdyk alone in front. He tucked a shot under Rask’s pads at 8:31.

On the ensuing shift, Bruins defenseman Kevan Miller fell down at center ice and Nylander broke in alone on a 2-on-1 rush before firing a wrist shot over Rask’s left shoulder. Bruins coach Claude Julien called timeout after the goal.

With McQuaid in the penalty box for holding, Nylander completed his hat trick and made it 4-1 by slipping a wrist shot into the net at 10:17.

But the Bruins rallied back. Pastrnak’s second goal came midway into the second. Krug’s score sliced it to 4-3 at 15:53. Boston had jumped in front 1-0 on Pastrnak’s goal 2:17 into the game, but Toronto tied it when Nylander collected Nazem Kadri’s pass, skated in alone and tucked the puck behind Rask.

Capitals 3, Canadiens 2

Montreal — Nicklas Backstrom scored in the third period, helping Washington beat Montreal.

Jay Beagle and Andre Burakovsky also scored for the NHL-leading Capitals (35-11-6). Braden Holtby stopped 20 shots.

Kings 1, Flyers 0 (ot)

Philadelphia — Peter Budaj posted his NHL-leading seventh shutout, Jeff Carter scored midway through overtime and Los Angeles won its fifth in a row.

Budaj, who wasn’t even on the Kings’ roster on opening night, extended his shutout streak to 144 minutes, 5 seconds. He made 17 saves.

Avalanche 5, Jets 2

Denver — Jarome Iginla had a goal and an assist, leading the Avalanche to a rare win. Colorado improved to 5-24-2 in its last 31 games. It also snapped a five-game skid at Pepsi Center, where it is 6-18-1 overall.

Sabres 4, Senators 0

Buffalo, n.y. — Robin Lehner made 37 saves, Kyle Okposo scored his 16th goal and Buffalo beat Ottawa to snap a three-game skid.

The Sabres also got goals from Ryan O’Reilly, Sam Reinhart and Marcus Foligno. Jack Eichel had two assists.

Lightning 3, Ducks 2 (so)

Tampa, Fla. — Brian Boyle scored in the fourth round of the shootout and Tampa Bay beat Anaheim.

Jonathan Drouin and Alex Killorn scored in regulation, Nikita Kucherov had two assists and Ben Bishop made 14 saves for the Lightning, who won the shootout 3-2 and improved to 4-9-2 over the last 15 games.

Devils 5, Blue Jackets 1

Columbus, Ohio — Taylor Hall scored twice, Travis Zajac had a goal and an assist and New Jersey beat Columbus. Jacob Josefson and Seth Helgeson also scored and Cory Schneider had 31 saves for the Devils, who won their sixth straight road game.

Hurricanes 5, Islanders 4 (ot)

New York — Ron Hainsey’s second goal of the game at 2:08 of overtime lifted Carolina over New York.

Jacob Slavin, former Dartmouth player Lee Stempniak and Teuvo Teravainen also scored to help Carolina win its third straight since the All-Star break.

Cam Ward made 33 saves.

Anders Lee, Casey Cizikas, Brock Nelson and Josh Bailey scored for the Islanders, who are 6-1-2 in their last nine games. Jean-Francois Berube gave up all five Hurricanes goals on 25 shots.