TORONTO -- William Nylander scored twice, including the winner, as the Toronto Maple Leafs defeated the Anaheim Ducks 7-4 at Air Canada Centre.

Auston Matthews also had a pair of goals for the Leafs (31-20-5), with Mitch Marner, Leo Komarov and Zach Hyman, into an empty net, chipping in.

But the win might have come at a cost.

Toronto starting goaltender Frederik Andersen left the game at the 6:15 of the second period after he was struck in the head by Corey Perry's left skate.

He made 25 saves on 28 shots before being replaced by backup Curtis McElhinney, who improved to 6-4 this season with 16 saves on 17 shots.

The detail of the injury and the severity is unknown, and no update was provided by the Leafs before the end of the game.

Nylander scored the second of his two goals while on a breakaway. His wrist shot beat Ryan Miller at 3:28 of the third period and was the eventual winner.

The Leafs opened the scoring in the first period when Matthews skated to Anaheim's net unabated. He then wrapped the puck around the goal past Ducks goaltender Miller at 6:32.

The Ducks (25-19-10) responded early in the second period. Rickard Rakell centred a pass to Ryan Getzlaf in front of the net. Getzlaf' shot beat Andersen 43 seconds into the period.

Nylander and Rakell traded goals for their respective teams before Ondrej Kase scored at 8:23 while on the power play to give Anaheim a 3-2 lead.

Toronto responded with a power-play goal of its own. Marner's snap shot put Toronto level with Anaheim 3-3 at 15:28.

Komarov also scored in the second when he tipped Jake Gardiner's shot past Miller to give Toronto at 4-3 lead at 17:40.

Rakell scored his second goal of the game in the third period when he found an opening above McElhinney's glove at 2:07 to tie the game 4-4.

Matthews scored his second goal of the game at 16:49. Hyman added an empty-net goal at 19:06.

Perry assisted on all four Anaheim goals.

Note: The Maple Leafs loaned defenceman Andreas Borgman to the Toronto Marlies, their minor-league affiliate, hours before puck drop. The rookie earned a spot out of training camp and has been on the Leafs roster until Monday. He recorded three goals and eight assists in 11 games.