TORONTO — A tournament that started with an 8-0 shellacking ended in triumph Monday with a bronze for Slovakia, only its second ever medal at the world junior hockey championship.

Captain Martin Reway set up three goals, including Pavol Skalicky's winner early in the third period, as Slovakia capped a remarkable competition by upsetting Sweden 4-2.

"Its huge for Slovakia, for everybody there," said Reway, a Montreal Canadiens' prospect. "Not only for the success this year but to start thinking that we can win big games like this. And (that) we don't only go to tournaments like this to lose games."

The Slovaks won their only other medal, a bronze, in 1998-'99, in Winnipeg. Eighth last year, they leave this tournament with wins over Finland, the Czech Republic, Germany and Sweden, losing only to Canada (twice including the 8-0 opener) and the U.S.

Slovak goalie Denis Godla, one of the stars of the tournament, raised his arms in triumph as the final buzzer went before he was mobbed by his teammates before a crowd of 13,625 at the Air Canada Centre.

Afterwards, he said making the quarter-finals was the Slovaks' goal. But he thought they could go further.

They did, dispatching the Czechs 3-0 before falling 5-1 to Canada in the semifinals.

For Sweden, which had won five straight games before falling 4-1 to Russia in Sunday's other semifinal, it was a sour end to a tournament.

"It's going to be a long flight home," said forward Axel Holmstrom.

Sweden came into the game with 17 tournament medals (2-10-5), including a gold and two silver at the three most recent editions.

Slovakia had a dream start, up 2-0 on goals by David Soltes and Mislav Rosandic after just three minutes 22 seconds. Outshot 5-0 and trailing, the Swedes reacted by calling a timeout.

"It felt almost like were trying to overdo stuff at the start," said Swedish coach Rikard Gronborg. "That's the reason why we had to take a timeout."

The smooth-skating Swedes began to get their act together and pulled even on goals by William Nylander and Jens Looke later in the period. The Swedes could perhaps have had more but were unable to pull the trigger on a five-on-three power play for 85 seconds.

Once trailing the shot count 7-2, Sweden finished the first period with a 15-10 edge.

The game turned at the start of the third, with the score still tied at 2-2.

The Slovaks started the period on a five-minute power-play after Julius Bergman received a major penalty for interference and a game misconduct for high-sticking Patrik Koys in the neck and face at the end of the second.

"That's not good in a situation where you have a tired team," said Gronborg.

Skalicky took advantage, beating goalie Linus Soderstrom between the legs from the slot after a perfect pass from Reway at 2:52.

Koys, who needed help to get off the ice after being hit by Bergman, returned in the third to get his revenge. Sweden pulled Soderstrom with 2:28 remaining, only to see Reway set up Koys for an empty-net insurance goal at 19:04.

"It's mistakes that cost us the game," said Nylander, who had seven shots on the night.

"We were lackadaisical with the puck," he added.

Both teams finished with 28 shots.

While there were empty seats, the game drew an enthusiastic crowd — most clad in red Canadian jerseys ahead of the gold-medal showdown — that cheered on Nylander every time the Toronto Maple Leaf prospect's name was announced. The stylish forward had a goal and six shots in the first alone.

While Slovakia has just 11,300 registered hockey players and 64 rinks, it has a developmental program that was home to 13 players on its tournament roster. They forged a team identity as Orange 20 Bratislava, playing against senior club competition.

"I didn't really expect that we were going to get a medal," coach Ernest Bokros said through an interpreter. "But we took it game by game.

"And we knew that we could play good defensively, But we also knew that if we wanted to be successful tonight we had to open up and play more offensive and score some goals."

Godla, given the hook against Canada on Boxing Day, came into the game with a 2.90 goals-against average and .925 save percentage. Godla, eligible for the 2015 NHL draft, led all tournament goalies in shots faced (214) and saves (198) going into play Monday.

The Slovak goalie was a fan favourite at the tournament, with the crowd chanting "goalie, goalie" in his honour.

"An unbelievable feeling," said Godla.

Follow @NeilMDavidson on Twitter