Detroit led 3-2 in the third period, but Cody Glass tied the game at 11:18 and Jack Hughes set up Jesper Bratt on a 2-on-1 break for the go-ahead goal at 16:26.
The Red Wings have missed the playoffs the past 10 seasons.
Bratt scored twice and had an assist, and Hughes had a goal and two assists for the Devils (41-36-3), who had lost two straight. Jake Allen made 25 saves.
Justin Faulk, David Perron and Emmitt Finnie scored for Detroit (41-30-9), which has lost six of eight (2-5-1). John Gibson made 27 saves.
Faulk gave the Red Wings a 1-0 lead at 9:41, taking a pass from Dylan Larkin and beating Allen through the five-hole with a wrist shot from the right face-off dot.
Hughes made it 1-1 at 10:40, putting a wrist shot over Gibson’s blocker from the right face-off dot for his 27th goal.
Perron put the Red Wings ahead at 11:59 of the second period, sweeping a one-timer off Johnathan Kovacevic’ stick and past Allen from the high slot.
Bratt made it 2-2 at 15:16, putting a long wrist shot through traffic inside the post for his 21st goal.
Finnie gave the Red Wings a 3-2 lead at 7:00 of the third period, jamming the puck over the line in a goal-mouth scramble, but Glass put in a rebound to make it 3-3 at 11:18.
After Hughes and Bratt gave New Jersey the 4-3 lead, Dawson Mercer scored into the empty net at 19:00 for the 5-3 final.