COPENHAGEN — Canada will compete for a medal at the world hockey championship for the fourth straight year thanks to another clutch goal from Ryan O'Reilly.

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.

"It was back and forth," said O'Reilly, who also scored the game winner that eliminated Russia in the 2017 semifinal in Cologne, Germany. "We had the lead multiple times and going forward we have to solidify those leads and not give anything up. But we showed good resilience, we kept scoring. We kept taking the lead and hitting the one in overtime was huge."

The Canadians will face Switzerland in the semifinals in Copenhagen on Saturday. The Swiss advanced with a 3-2 upset of Finland on Thursday.

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.

"We may not have been great through the group stage but we were dangerous tonight," said Canada captain Connor McDavid, who picked up primary assists on all three power-play goals and now has 16 points in eight tournament games. "We did a lot of good things."

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 McDavid, O'Reilly, Aaron Ekblad and Parayko, with O'Reilly's goal ending the game.

"I didn't do too much on the play, I just stood there with my stick," said O'Reilly. "I still don't know how (McDavis) got it through on my tape like that."

Final shots were 41-30 in favour of Canada.

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.

The other semifinal will feature the united States and Sweden. The Americans remained in the hunt for its first medal since 2015 after a 3-2 win over the Czech Republic in Herning, while the Swedes edged Latvia 3-2.