The defending Stanley Cup champion Bruins rallied from a two-goal deficit in the third period and finished the regular season with back-to-back victories.
Boston closed out the campaign as the No. 2 seed in the Eastern Conference and awaited the results from late Saturday to learn its first-round playoff opponent.
Buffalo had a 3-1 lead as the game approached the midway point of the third period, but Tyler Seguin brought the Bruins within one by scoring on the power play. Brad Marchand tied it with 7:39 to play.
Bergeron beat Jhonas Enroth between the pads for the winning goal in the shootout.
Tim Thomas, who led Boston to the NHL title a year ago, stopped 25 shots in the regular-season closer. Enroth made 37 saves.