BOSTON -- Milan Lucic had no clue how much time was remaining when he began Boston's final rush of the game.
David Krejci thought there was more than there actually was.
Adam McQuaid looked at the clock and knew precisely what to do.
His desperation fling to the front of the net deflected off the stick of Krejci and past San Jose goaltender Antti Niemi with 0.8 of a second remaining on Thursday night, leading the Bruins to an improbable 2-1 victory over the Sharks.
San Jose had been the league's last remaining unbeaten team in regulation.
"It was seven seconds left when I looked," McQuaid said. "I had an idea that there wasn't much time left.
"We were cutting it pretty close in that situation. I don't think you can get much closer."
Jerome Iginla scored his first goal in a Boston uniform and Tuukka Rask stopped 38 shots for the Bruins, who won their fourth consecutive game and first at home against the Sharks since Dec. 23, 2002.
"I think early on in the season, we're learning how to win games in different ways," Krejci said. "Today was one of them."
It sure was.
San Jose, which entered the game leading the league in points (17) and goals (39), appeared to be on the verge of stretching its streak of not losing in regulation to 10 straight games to start the season.
Despite being outshot 39-17, the Bruins (7-2-0) put a stunning end to that.
Lucic carried the puck into the right corner and eventually sent a pass back to the blue line to McQuaid, whose last-ditch flick toward the crease tipped off Krejci's stick and through the legs of Niemi, sending the crowd in delirium.
"Honestly, when the rush started, I had no idea how much time was left on the clock," Lucic said. "It was probably a better thing because when I got the puck back in the corner on the forecheck, I probably would have just threw it on net and tried to create a play there."
Krejci, who extended his point streak to six games, already was thinking about overtime, and thought there was 15 or 20 seconds remaining when he scored.
"Usually it happens when you score in overtime, it's a pretty special feeling as well," Krejci said. "It was even maybe more special, especially against a team like that."
Patrick Marleau netted his team-high eighth goal of the season for San Jose and Niemi stopped 15 shots.
Iginla snapped a scoreless tie with 1:12 remaining in the second period, corralling a wide shot by Dennis Seidenberg that caromed off the back boards and one-timing it through Niemi's legs.
"You keep thinking, 'It could be this one.' It's nice to have that feeling out of the way," Iginla said. "I was pretty excited to get my first in a Bruins uniform and get it at home and get in a tough game, and to get it unexpectedly.
"It's been a while. You always hope it's coming."
The lead didn't last long, though.
San Jose (8-1-1) knotted the score 18 seconds into the third period when Marleau casually flipped a rebound over a sprawling Rask, and it remained that way until Krejci's heroics.
"The objective is to score every shift, right?" Lucic said. "You try to keep plugging away, plugging away and hope that it works for you.
"Hopefully, we can continue to find ways to score."
Despite the rare matchup between two of the top teams in the league, TD Garden was only three-quarters full, likely due to Game 2 of the World Series between the St. Louis Cardinals and Boston Red Sox taking place just three miles away.
The fans who didn't make it missed out on a thriller.
"We could have had a little more polish around the net, but it's still a loss and that's unacceptable, especially in the situation we were," Sharks coach Todd McLellan said. "We can't leave here saying the hockey gods or we could have or should have, because could have and should have never won any games."
NOTES: Boston RW Loui Eriksson, who left Wednesday's win over Buffalo in the third period after being blindsided by Sabres D John Scott, was diagnosed with a concussion and will be out indefinitely, according to a statement issued by Bruins GM Peter Chiarelli. Eriksson, who had played in 148 straight games, stayed in Buffalo on Wednesday night and traveled to Boston on Thursday with a member of the Bruins' medical staff. He has two goals and an assist in his first season in Boston. Meanwhile, Scott was suspended indefinitely by the league and given the opportunity to attend a disciplinary hearing, which has not yet been scheduled. ... Brothers Dougie (Boston) and Freddie Hamilton (San Jose) faced each other for the first time after Freddie was recalled earlier in the week and played his first NHL game on Monday. ... The Sharks were 4-0-1 in their previous five games against the Bruins. ... San Jose is 5-2-1 against Boston since the Bruins traded C Joe Thornton to the Sharks in 2005. Thornton has five points in eight games against his former team.