Nylander won it with a wrist shot from the high slot past Detroit goalie Alex Lyon.
Auston Matthews had a goal and an assist, and Mitchell Marner had two assists for the Maple Leafs. Ilya Samsonov made 20 saves.
Nate Danielson, Jonatan Berggren and Dominik Shine scored, and Shayne Gostisbehere had two assists for the Red Wings. Lyon made 34 saves.
Nylander gave Toronto a 1-0 lead during a 4-on-4 situation at 3:24 of the first period, but Danielson quickly tied it 1-1 on a deflection at 5:46.
Berggren gave Detroit a 2-1 lead with a power-play goal at 11:15.
Matthews answered with a power-play goal of his own, finishing off a tic-tac-toe passing play to tie it 2-2 at 19:52.
Tyler Bertuzzi scored his first of the preseason to give the Maple Leafs a 3-2 lead at 8:12 of the second period.
Shine tied it 3-3 at 18:25 after Samsonov turned the puck over behind the net.