Each of the Bruins' two regulation losses this season have come against the Red Wings, who won 5-4 in Detroit on Nov. 4.
"It's a big feat," Red Wings captain Dylan Larkin said. "It's pretty amazing what these guys have been able to do early in the season again, and we've [defeated] them twice now, and I think this is a big one for us. Winning in this building, and an emotional game."
Compher gave Detroit a 1-0 lead at 5:13 of the first period on the power play, tipping in Gostisbehere's point shot.
DeBrincat made it 2-0 at 15:01, stripping the puck from Bruins forward Matthew Poitras at Boston's blue line and skating in on a breakaway.
DeBrusk cut it to 2-1 at 3:00 of the second period with a power-play goal, scoring on a rebound in front. He has goals in back-to-back games after having one in his first 16 this season.
"It's always good to see it go in," DeBrusk said. "You want to do it in a winning manner, though, which obviously didn't happen. It's been hard to get those in the net this year, so it's nice to have back-to-back [goals], personally."
Robby Fabbri extended the lead to 3-1 at 13:24 with a one-timer from the right face-off circle off a cross-ice feed from Daniel Sprong.
Heinen cut it to 3-2 at 4:12 of the third period. Mason Lohrei sent the puck off the end boards, and it rebounded to Heinen for the goal
Larkin pushed it to 4-2 with a power-play goal 55 seconds later at 5:08.
Detroit went 2-for-6 on the power play against Boston's League-best penalty kill (91.0 percent entering Friday), and Fabbri's goal was scored shortly after a penalty expired on another chance. Boston has allowed two power-play goals in two games this season, each against Detroit.
"I really thought the group did a good job of digging in after that [Heinen's goal]," Red Wings coach Derek Lalonde said. "And again, the momentum the power play can get you when it's clicking."