Boston played with four defensemen for part of the third period after Zdeno Chara and Torey Krug left with injuries. Forward Jake DeBrusk also left early in the third.
"We knew it was a big ask to come back, and we talked about it after the second period," Boston coach Bruce Cassidy said. "'Listen, we just have to play better than the guy across from you. Outcompete him, win some pucks. We may or may not win the game, but that's just the way we need to play,' and we were able to do it."
The Hurricanes (30-29-11) have lost four of their past five (1-4-0) and remain seven points behind the New Jersey Devils for the second wild card into the Stanley Cup Playoffs from the Eastern Conference.
"I'm still kind of stunned really," Hurricanes forward Justin Williams said. "Things can go so right for 50 minutes and you can dig in. Then you let one goal turn into another one and then another one."
Brad Marchand's 30th goal of the season gave the Bruins a 1-0 lead with 11 seconds remaining in the first period. Pastrnak carried the puck behind the net and left a drop pass for Marchand, who scored at the right post. Marchand reached the 30-goal mark for the third straight season.