Down 4-3, Tavares knotted things up with 7.6 seconds left in regulation when he tipped a shot from the point by Jake Gardiner past Bernier for his 24th of the season with Sparks on the bench for the extra attacker.
Tavares then nearly won it a minute into overtime, but he shot high over Bernier’s net from close range before Kapanen won it.
Tied 3-3 through 40 minutes, Nazem Kadri had a chance right at the end of a Toronto power play in the third period, but his try to redirect a pass from William Nylander hit the crossbar.
Nielsen eventually snapped the deadlock with under eight minutes to go when he buried a rebound past Sparks, who was making his first start for Toronto since allowing five goals on 32 shots in Detroit’s 5-4 overtime victory at Scotiabank Arena on Dec. 6.
Detroit led 2-1 after the first and stretched that advantage at 9:53 of the second when Ehn took a long pass from Wade Megan before fighting off both Travis Dermott and Justin Holl and chipping a backhand over Sparks for his first NHL goal in his 22nd game.
A sluggish Toronto team got some life thanks to its fourth line 2:59 later. Gauthier scored his first goal of the season off a pass from Par Lindholm. Trevor Moore, called up from the Toronto Marlies of the AHL after winger Tyler Ennis broke his ankle on Saturday, picked up the second assist for his first NHL point in his debut.
The Leafs, who came in having scored 18 goals during a three-game winning streak, then tied the game with six minutes left in the second. Tavares took a pass and drew the puck up between his own skates before whipping a feed to Rielly, who beat Bernier high for his 13th.
Rielly leads all NHL defenseman in goals and points (44). He now has three goals and eight assists during a five-game point streak.
The Leafs got their first power play late in the second, but Kadri hit the post on a tip of a shot from the point by Gardiner.
Toronto got off to a fast start as the new second line of Kapanan, Nylander and Auston Matthews connected 27 seconds into the first.
Bernier was there to stop the initial shot from Matthews, but Kapanen outmuscled Red Wings defenseman Trevor Daley and scored his 13th.
Detroit got that one back at 3:45.
The Red Wings pushed ahead with 41.8 seconds left in the period on a delayed penalty when Rasmussen tipped a shot from Dylan Larkin for his sixth goal of the season as Detroit outshot Toronto 14-3 in the opening 20 minutes.
NOTES: Bernier played three seasons with the Leafs from 2013 to 2016. … Detroit center Andreas Athanasiou (upper-body injury) missed his second straight game. … Red Wings defenseman Trevor Daley played the 1,000th game of his NHL career.
Red Wings: Host Pittsburgh Penguins on Thursday.
Maple Leafs: At Columbus on Friday.
More AP NHL: https://apnews.com/tag/NHL and https://twitter.com/AP_Sports