IMATRA, Finland - Mitch Marner scored with less than four minutes to go to cap the scoring in a wild third period, and Canada edged Sweden 7-6 Wednesday in its last exhibition match before the world junior hockey championship.

Canada led 5-1 heading into the third, before Sweden lit up Canada goaltender Mason McDonald with five goals over the final 20 minutes.

"We put ourselves in a very good position after two periods, and we just have to continue to play and have the ability to close out leads," Canada coach Dave Lowry said.

Marcus Pettersson's second goal of the period at 15:26 tied the game at 6-6 before Marner's goal salvaged the win for Canada.

McDonald recovered to make some big saves over the final minutes with Sweden pressing for the tying goal. He ended up stopping 26 of 32 shots.

"He gave us a chance," Lowry said of his goaltender. "He made saves, and he made timely saves."

Vancouver Canucks forward Jake Virtanen had two goals for the Canadians, with Dylan Strome, Mitchell Stephens, Haydn Fleury and Brendan Perlini also scoring.

Oskar Lindblom, Jacob Larsson, Axel Holmstrom and Adrian Kempe had Sweden's other goals.

Linus Soderstrom gave up five goals on 20 shots before being replaced by Erik Kallgren, who stopped five of seven shots in relief.

Canada opens its defence of the world junior title Saturday against the rival United States in Helsinki, Finland.