Jake DeBrusk and Brad Marchand score two goals each as B's post third straight win.

BOSTON -- It wasn’t over ‘til it was over, but when it finally was, two-goal nights from Jake DeBrusk and Brad Marchand were enough for the Bruins to hold off the relentless Flames on Thursday night at TD Garden, 6-4.

The Bruins, who opened a four-game homestand with their third straight win, had leads of 4-2 and 5-3 in the third period, but the Flames closed within a goal both times. DeBrusk’s second of the night (13th of the season) made it 5-3 with 6:14 to play; Marchand’s second (15th this season) found an empty net with less than two minutes to play.

Jaroslav Halak made 33 saves for the B’s, who were outshot, 37-27.

Although coach Bruce Cassidy said in the morning that the Bruins’ habit of surrendering shorthanded goals (eight; tied for last in the NHL entering the game) had been a topic of discussion, they didn’t get the message. A two-man advantage covering 1:55, with another minor penalty tacked on, somehow turned into a 1-0 deficit at 7:46.

Michael Frolik, caught tripping David Krejci at 5:39, stepped out of the box with teammate Elias Lindholm (double minor, high sticking, 5:44) still inside, followed teammate Mark Jankowski on a shorthanded rush and scored on a rebound when Jaroslav Halak mishandled Jankowski’s playable shot from the left circle. It was the Flames’ league-leading 13th shorthanded goal.

The Bruins, who brought the NHL’s fourth-best power play into the game, at least managed to answer during Lindholm’s penalty, when second unit defenseman John Moore beat Mike Smith to the far side from the right circle at 9:02. The B’s took their first lead with 5:41 left in the period when Krejci, who missed the morning skate to be with his wife as she delivered a baby boy, snapped a shot from near the point that Jake DeBrusk tipped through Smith from the slot for his 12th goal of the season.

The Bruins still had a one-goal lead by the end of the second, despite allowing an early goal and spending more than six minutes killing penalties.

Calgary’s Johnny Gaudreau, who was denied by Halak on a first-period breakaway, got his second of the game near the one-minute mark. Halak trapped it on the goal line with his right skate blade, but the play wasn’t blown dead and Lindholm jammed it across the goal line at 1:05. The 2-2 tie lasted just 36 seconds, though: Torey Krug spotted Marchand coming out from behind the Flames’ net to Smith’s left, and hit him with a perfect slap-pass that Marchand steered home at 1:41 for his 14th goal of the season.

The B’s weren’t able to add to the lead, however, because they took four straight penalties before the Flames were assessed another. The biggest challenge came when, 1:18 into dealing with DeBrusk’s high-sticking minor, the Bruins were caught with too many men on the ice, leaving them at a 3-on-5 disadvantage for 42 seconds. Zdeno Chara, defense partner Brandon Carlo and Patrice Bergeron killed that off, and the B’s were in the process of killing a Marchand minor when Lindholm interfered with Sean Kuraly at center ice with just seven seconds left in the second. That became a third-period power play during which David Pastrnak made it 4-2 after just 54 seconds.