Brian Rolston and Travis Zajac each added two assists for the Devils, winners of eight of their last 10 games.
Claude Giroux scored for the Flyers, who have only two wins in their last 12 games.
Bergfors scored a pair of power-play goals as the Devils jumped out to a 3-0 first-period lead. The Swedish rookie put New Jersey on the board at 2:33, splitting the defense to beat Brian Boucher with a shot between the pads.
Bergfors struck again at 12:31, knocking in Travis Zajac's rebound.
The two goals gave Bergfors 11 for the season, second among rookies behind John Tavares of the Islanders.
Elias got the third goal at 15:47, the 300th of his career. The score reflected the level of play in the period as the Devils outshot the Flyers 14-5. Brodeur preserved the shutout with a stellar glove stop on Arron Asham midway through.
Philadelphia played a much sharper second period, outshooting New Jersey 12-5. Brodeur, under considerably more pressure, twice robbed Jeff Carter. The second save was spectacular-Brodeur dove out of the crease to poke check the puck off Carter's stick on a short-handed breakaway bid.
Philadelphia's persistence finally paid off as Giroux netted a power-play goal on a sharp-angle shot from the left circle at 15:03.
The Flyers were back in the game, trailing only 3-1. Then came the backbreaker with 33.1 seconds left: Elias netting his second tally on a two-on-one break with Rolston for a 4-1 Devils lead.
NOTES: The game concluded a busy stretch for both teams. The Flyers played four times in a span of six days while the Devils had three games in four nights. ... Elias is second on the Devils' goal list, trailing only John MacLean at 347. ... Flyers LW Dan Carcillo sat out the final contest of a four-game suspension handed down by the NHL for sucker-punching Washington's Matt Bradley. ... Brodeur had an assist on the Bergfors' first goal.