Krejci deflected Adam McQuaid's shot into the goal with 0.8 seconds remaining to give the Bruins their fourth straight win, ending the Sharks' record as the only team without a defeat in regulation.
The centre had earlier assisted Jarome Iginla's second-period opener, which was cancelled out by Patrick Marleau for the Sharks, who out-shot the Bruins 39 to 17 but found goaltender Tuukka Rask (38 saves) in prime form.
Dwight King scored a hat-trick as the Los Angeles Kings beat the Phoenix Coyotes 7-4 despite throwing away a four-goal lead.
King scored two of Los Angeles' four first-period goals as they stormed into a commanding lead, but Martin Hanzal netted twice to help bring the Coyotes back level with 2:50 gone in the third.
However, Mike Richards, Matt Frattin and King all tallied in the last 16 minutes to spare the Kings' blushes.
Martin St Louis scored an overtime winner as the Tampa Bay Lightning edged out the Chicago Blackhawks 6-5.
St Louis also had an assist, while Steven Stamkos had two goals and two assists for the Lightning, who had been heading for the victory in regulation until an own goal at 18:11 in the third, which was credited to Jonathan Toews.
Goals from Nino Niederreiter, Zach Parise and Dany Heatley gave the Minnesota Wild a 3-1 win over the Carolina Hurricanes.
Both goalies - the Hurricanes' Cam Ward and Josh Harding of the Wild - exited the game with injuries.
Braydon Coburn scored a third-period winner as the Philadelphia Flyers snapped their four-game losing streak by beating the New York Rangers 2-1.
Steve Mason made 31 saves for the Flyers, while Matt Read opened the scoring in the first, only for Brad Richards to level.
Alex Ovechkin became the first player to reach double figures this season with his 10th goal in the Washington Capitals' 4-1 victory over the Edmonton Oilers.
Mike Santorelli scored the only goal of the shootout as the Vancouver Canucks beat the New Jersey Devils 3-2.
Craig Smith's overtime winner saw the Nashville Predators to a 3-2 victory over the Winnipeg Jets, while Alex Chiasson and Jamie Benn had two goals apiece in the Dallas Stars' 5-1 triumph over the Calgary Flames and the Montreal Canadiens beat the Anaheim Ducks 4-1.