OSTRAVA, Czech Republic — Linus Oberg scored the go-ahead goal midway through the second period, and Sweden held on to beat Finland 3-2 on Sunday for the bronze medal at the world junior hockey championship.

Toronto Maple Leafs prospect Rasmus Sandin also scored for Sweden and tournament scoring-leader Samuel Fagemo supplied the other goal.

Fagemo, a second-round pick by the Los Angeles Kings last year, finished the tournament with eight goals and 13 points.

He and Oberg scored less than three minutes apart to give Sweden a 3-2 lead heading into the third period.

Sweden was dropped into the bronze-medal game after losing its semifinal to Russia in overtime a day earlier. Finland lost to Canada in its semi.

"It feels a lot better than Saturday," said Sandin. "We were very disappointed after (the Russia) loss.

"We came together pretty quick. It was great to win this one."

Patrik Puistola and Matias Maccelli scored first-period goals for Finland, which won the tournament last year.

"Losing in sudden death to the Russians was tough, but to come back strong and win the bronze medal, it's been fun," said Swedish centre and Dallas Stars prospect Oskar Beck.

"It's tough. In the first period we didn't play good. We came out as Sweden in the second period."

Swedish goaltender Hugo Alnefelt made 21 stops, including a huge glove save on Finnish captain Lassi Thomson with six seconds left.

Finland, which pulled goalie Justus Annunen for the extra attacker with about a minute to go, had a flurry of late opportunities but couldn't get past Alnefelt.

"I'm so disappointed. I expect more from us," said Thomson, an Ottawa Senators first-round pick.

Annunen finished with 18 saves.

The Swedish team, which has three silver medals since 2013, earned bronze at the 2010 tournament before losing four straight third-place games. Sweden's lone world junior gold came in 2011.

Finland had won three gold medals at the tournament since 2014 and last won bronze in 2006.

Sampo Ranta was named Finland's player of the game while Fagemo took that honour for Sweden.

Earlier Sunday, Germany avoided relegation by beating Kazakhstan 6-0 in the third game of a best-of-three series.

Dominik Bonk scored twice for the Germans, who had a four-goal second period to help secure a spot in next year's tournament in Edmonton and Red Deer, Alta. Austria has been promoted to the 2021 event.

Germany won the first game of the series earlier this week before Kazakhstan bounced back, claiming its first victory of the tournament on Saturday to set up Sunday's clash.