SOCHI, Russia -- Daniel Alfredsson scored a go-ahead goal late in the second period and Sweden went on to beat Latvia 5-3 Saturday, staying undefeated and earning an automatic spot in hockey quarterfinals at the Olympics.

The Swedes (3-0) will get to rest until Wednesday when the top eight teams will begin playing the single-elimination portion of the tournament.

The Latvians (0-3) will have to win Tuesday in the qualification round to earn a spot in the quarterfinals after being relatively competitive in their three losses.

Sweden's Henrik Lundqvist made 20 saves.

Latvia's Kristers Gudlevskis stopped 25 shots.

Patrik Berglund put the Swedes ahead 1-0 in the first and Lauris Darzins tied it late in the period.

advertisement | advertise on newsday

Janis Sprukts put Latvia ahead early in the second, but the lead didn't last long because Erik Karlsson pulled Sweden into a 2-all tie.

Alfredsson's goal put the short-handed Swedes ahead for good late in the second period and Jimmie Ericsson gave them a two-goal lead later in the period.

Latvia's Zemgus Girgensons pulled his overmatched team within a goal early in the third, but Alexander Edler sealed the win for Sweden midway through the final period.