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 in Finland.

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 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.

Canada plays its first tournament game Saturday against the United States at 1 p.m. ET.