Jordan Eberle, Nazem Kadri and Brandon Kozun scored in a shootout, and Jake Allen made the one stop he needed to give Canada a 5-4 victory over the United States on Thursday night in the world junior hockey championship.

After the first five shooters scored, Allen stopped Jordan Schroeder's attempt, then was mobbed by his teammates after the comeback victory.

"Adversity's huge," Eberle. "It's what makes your team better and it's what makes hockey fun. And it's going to help us in the long run."

Five-time defending champion Canada and the United States each won their first three games to set up the round-robin finale for the top spot in Group A.

"Maybe people will say we didn't play well, but we did, it's just that the U.S. played unreal," Canadian coach Willie Desjardins said. "We were lucky tonight."

Canada will play the Russia-Switzerland quarterfinal winner in the semifinals Sunday. The United States will face Finland in the quarterfinals Saturday, with the winner advancing to face Group B winner Sweden on Sunday night.

"We had them right where we wanted them," Schroeder said. "We let it slip at the end, but that's part of hockey. We have to move forward. If we can get through Finland and Sweden, hopefuly we'll see them in the championship game. It was a good test for both of us. Now we know that we stood up against them and we know we can take them."

The United States had a 4-2 lead in the third period, but Eberle scored his second goal of the game at 10:03, and defenseman Alex Pietrangelo tied it with a short-handed goal with 4:15 left.

"Good teams find a way to win and we kept battling," Pietrangelo said.

Schoeder and Tyler Johnson had short-handed goals for the United States in the second period. Philip McRae and Danny Kristo also scored for the Americans.

Stefan Della Rovere added a goal for Canada.

In Regina, Jacob Markstrom made 39 saves in Sweden's 7-1 victory over Finland.

"It was a good start for me," Markstrom said. "I got a lot of shots and I felt good out there and I really enjoy it. That's what I'm there for. I don't think a lot, I just go out there and try and take the puck. It's the best thing."

Jacob Josefson had two goals, and Andre Petersson, Dennis Rasmussen, Mattias Tedenby, Magnus Paajarvi-Svensson and Marcus Johansson also scored for Sweden (4-0). Teemu Hartikainen scored for Finland (2-2).

In the late Group B game in Regina, Vladimir Tarasenko had two goals and an assist, and Igor Bobkkov made 39 saves in Russia's 5-2 victory over the Czech Republic.

Russia (3-1) will face Switzerland (2-2) in the quarterfinals, while the Czech Republic (1-3) dropped into the relegation round.

In Group A in Saskatoon, Nino Niederreiter scored twice, and Benjamin Conz stopped 39 shots to help Switzerland beat Slovakia 4-1.

Richard Panik scored for Slovakia (1-3).