Carey Price made 15 saves for the defending Olympic champion Canadians, who were stretched to the limit by Latvia goalie Kristers Gudlevskis.
The 21-year-old Tampa Bay Lightning prospect made 55 saves in a spectacular performance, nearly pulling one of the biggest upsets in hockey history largely by himself.
But Weber unleashed his peerless slap shot late in a power play, and Canada finally took the lead on its 54th shot against Gudlevskis.
Canada advanced to a semifinal meeting with the United States in a rematch of the gold-medal game in Vancouver four years ago.
(Copyright 2014 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.)