ST. PETERSBURG, Russia — The Czech Republic topped Group A at the world ice hockey championship by beating a flattered Switzerland 5-4 on Tuesday.

Switzerland needed to win to advance. Instead, Denmark's spot in the quarterfinals was confirmed for only the second time.

The Czechs, seeking their first title since 2010, learned their will play the United States in the quarters, even though the Americans lost their last group game to Slovakia 3-2 in overtime.

Slovakia would have qualified instead of the Americans with a win in regulation, but the U.S. earned a point for forcing overtime, enough to secure fourth place in Group B.

The Canadians and Finns were the only unbeaten teams left in the tournament, and met late Tuesday to decide first place in Group B.

Germany also advanced from the group.

Also advancing from Group A were Russia, Sweden, and Denmark.

Switzerland, thoroughly dominated by the Czech Republic, fought back from 3-1 down early in the third then 5-2, with a pair of late goals.

Slovakia took the lead against the U.S. on a first-period wrist shot from Christian Jaros, but forward Brock Nelson tied it up off a pass from David Warsofsky.

Nick Foligno put the U.S. in front 2-1 early in the third but Pavol Skalicky turned Tomas Marcinko's shot into the net to make it 2-2. Slovakia pulled goaltender Julius Hudacek in an attempt to win the game in regulation and take the Americans' quarterfinal place, but the U.S. held on.

Marko Dano scored the game-winning goal for Slovakia as both teams finished the preliminary round with 3-4 records.

Kazakhstan and Hungary will be relegated from the top level of the world championship for next season. The Kazakhs' relegation was assured last Saturday, while Hungary was condemned on Tuesday following Belarus' 3-0 win over France.