Brandon Dubinsky scored with 4:05 left in the game to pull the Rangers within a goal. They failed to tie the game despite having a two-man advantage for 44 seconds late in the third and being on the power play to end the game.
Datsyuk's second-period goal allowed Detroit to avoid getting shut out in three straight games for the first time in franchise history.
Detroit's Jimmy Howard stopped the first 32 shots he faced and finished with 45 saves.
Martin Biron, making his second straight start in place of Henrik Lundqvist, stopped 32 shots for the Rangers.
Detroit snapped out of a scoreless funk by scoring three times after getting blanked in back-to-back games.
The Rangers haven't won in regulation since beating Toronto on Jan. 19 and are mired in their worst slump of the year, going winless in five games.
New York's Derek Stepan tied the game 1-all at the 3:09 mark of the final period and Jiri Hudler, with an assist from Datsyuk, put the Red Wings back ahead a couple minutes later.
Miller seemed to seal an easy victory when he scored with 5:23 left in the game, but Dubinsky scored about a minute later.
Former Red Wing Sean Avery drew two high-sticking penalties late in the game, getting hit in the face both times, but the Rangers couldn't take advantage of the opportunity to make it 3-all and force overtime.
On the same night the Red Wings welcomed back Datsyuk, they lost another player when Valtteri Filppula was knocked out of the game with a lower-body injury.
Notes: The Red Wings are 18-0-2 when leading after two periods, but barely held on for the latest such victory against the NHL's best team when trailing after two periods. ... New York's Chris Drury (left knee) missed his second straight game. ... Detroit's Tomas Holmstrom might be able to return to the lineup on Wednesday against Nashville. ... The Rangers haven't won at Joe Louis Arena since 1999.