COPENHAGEN -- Canada will compete for a medal at the world hockey championship for the fourth straight year.

Ryan O'Reilly scored the game winner on a 4-on-3 power play with 4:57 into overtime Thursday as Canada beat Russia 5-4 and punched its ticket to the semifinals in Copenhagen.

Colton Parayko and Ryan Nugent-Hopkins also scored power-play goals while Kyle Turris and Pierre-Luc Dubois added third-period markers.

Canada came into the quarterfinal as the lower seed after a somewhat lacklustre preliminary-round performance in small-town Herning. The change of scenery seemed to agree with the Canadians in their first period of action at Royal Arena in Copenhagen.

Canada controlled the play, outshooting Russia 12-4 in the opening frame and taking a 1-0 lead when Parayko fired a massive slapshot to the glove side of Igor Shestyorkin at 4:45.

The power-play goal snapped a 0-for-16 drought that had stretched over four preliminary-round games for Canada. It was the first of the tournament allowed by Shestyorkin, who had been perfect in seven periods of action against Slovakia, Belarus and Austria during preliminary-round play.

The 22-year-old was a surprise starter in place of the more experienced Vasili Koshechkin, who held down the No. 1 job for the gold medal-winning Olympic Athletes from Russia team at the Pyeongchang Games in February.

Darcy Kuemper made his fifth start of the tournament for Canada.

The Russians started skating in the second period, building an 8-3 shot advantage before Nugent-Hopkins put Canada up 2-0 while Sergei Andronov was serving his second penalty of the game at 11:51 of the second period.

The Russians stormed back with a goal just 1:02 later when Ilya Mikheyev scored after an Artem Anisimov shot pulled Kuemper out of position. Alexander Barabanov evened the score with an extra attacker on the ice for a delayed penalty call with 2:28 left to play in a second period where Russia outshot Canada 15-9.

After a cautious start to the third, Turris put Canada up 3-2 at 7:11, beating a sprawling Shestyorkin between the pads from the slot after a pinpoint pass from Jaden Schwartz.

Andronov answered back for Russia just 1:33 later, deflecting a Nikita Zaitsev shot over Kuemper's shoulder. Then, Dubois scored his third of the tournament off a rebound off a Tyson Jost shot with 7:24 left to play in the third before Anisimov forced overtime when beat Kuemper high from a bad angle.

The teams traded chances in overtime before Canada went to the power play after Kirill Kaprizov was whistled for slashing with 3:35 elapsed. Canadian coach Bill Peters called a time out, then sent out captain Connor McDavid with O'Reilly, Aaron Ekblad and Parayko, with O'Reilly's goal ending the game.

Canada has now won its last three meetings with Russia at the worlds, storming back for a 4-2 come-from-behind win in the semifinal in Cologne, Germany in 2017 and earning gold with a 6-1 win over Russia in 2015.

The win also ends a four-year medal streak for the Russians at worlds, where they won gold in 2014, silver in 2015 and bronze in 2016 and 2017.

In the other early quarterfinal in Herning on Thursday, the United States remains in the hunt for its first medal since 2015 after a 3-2 win over the Czech Republic. Thursday's late games will see Sweden clash with Latvia in Copenhagen, while Finland meets Switzerland in Herning.

Canada will face the winner of Finland versus Switzerland in Copenhagen in semifinal action on Saturday.