COLOGNE, Germany -- Trailing by two goals with 20 minutes to play, the mood was tense in the Canadian locker-room on Saturday at the world hockey championship. A light-hearted comment helped the two-time defending champions refocus and it paid off with a 4-2 comeback victory over Russia.

"When we walked into the room, there was a little tension," said Canada coach Jon Cooper. "Then somebody blurted out, 'It's OK boys. We've got 'em right where we want 'em.' It calmed the whole room down.

"We took a breath in the locker-room and went out and scored a power-play goal (right away). Right then you could see the weight go off their shoulders. Then we played a heck of a third."

The Canadians scored three more unanswered goals at Lanxess Arena to secure a berth in the gold-medal game. They will go for a third straight title Sunday against Sweden, a 4-1 winner over Finland in the other semifinal.

Russia will play Finland for the bronze.

Canada outshot Russia 19-4 in the final period and kept consistent pressure on netminder Andrei Vasilevskiy. Mark Scheifele halved the Russian lead 17 seconds into the frame and Nate MacKinnon tied it with 4:53 left to play.

Ryan O'Reilly scored the go-ahead goal with 3:02 remaining and Sean Couturier iced it with an empty-net goal with 67 seconds left.

"I think in the (second) intermission, we focused on getting a spark," said O'Reilly. "We needed something to get us going, whether it was a couple of good chances or scoring a goal."

Evgeny Kuznetsov put Russia on the board at 12:16 of the second period when he beat Canadian goalie Calvin Pickard after a pretty passing play. It was the first time in the tournament that Canada failed to score the opening goal.

Nikita Gusev made it 2-0 at 14:50 after another tic-tac-toe effort in the Canada zone. He actually fanned on the shot but it still fluttered past Pickard.

"The first period was more of a feeling-out process," said Canadian forward Wayne Simmonds. "Second period -- that wasn't us. We wanted to show what we could really do. I thought the third period illustrated that."

In the third, MacKinnon set up a power-play goal by feeding the puck through to a wide-open Scheifele in the slot, who one-timed it over Vasilevskiy's glove hand.

"Suddenly it was a different game," Russian forward Artemi Panarin said of Canada's first goal. "We got nervous, and that's why we lost."

MacKinnon tied the game when he swept the puck in by the goalfront and O'Reilly banged in a loose puck moments later. O'Reilly then delivered a long pass to Couturier for the empty-netter that sealed the win.

"I've been extremely fortunate as a coach to be able to coach in the National Hockey League and be able to coach in the Stanley Cup final," said Cooper, who's coaching Canada for the first time. "That was one of the greatest hockey games I've ever been a part of.

"I thought every single Russian player played as hard as they possibly could, just as every Canadian player (did). When you're playing as hard as you can, that's all you can really ask from the guys."

Canada outshot Russia 38-28 overall.

"I don't think there was one goal in that game that was a bad goal," Cooper added. "The goalies all made the saves they had to and really good players beat them. That's why it was a good hockey game."

Canada hasn't won three straight gold medals at this event since the early 1950s. The Czech Republic was the last team to three-peat (1999-2001).

"This is a big win for us but we're not done yet," said O'Reilly, who helped Canada win gold in Prague in 2015 and in Moscow last year. "We've got a lot of work left."

The Canadians are bidding to match the 27 titles won by Russia or the Soviet Union. Sweden won its ninth and last title in 2013.

Sweden got off to a great start when Nicklas Backstrom set up Alexander Edler inside the first two minutes before Joonas Kemppainen equalized for Finland.

The Swedes made the most of penalties to go ahead in a bad-tempered second period. Valtteri Filppula went off for tripping and John Klingberg scored straight away on the power play, before William Nylander made the most of another with another Backstrom assist.

The second period ended in a brawl and both teams had players penalized for roughing.

Finland pushed hard in the final period but Joakim Nordstrom sealed it with six minutes remaining.