Poland international Grzegorz Rasiak snapped up his 14th goal of the season as Derby came from behind to stay in the play-off hunt.
George Burley's side claimed their sixth away win in a row to send bottom club Rotherham headlong towards the drop.
Rotherham took a shock lead from the spot but Rasiak levelled and Marcus Tudgay gave the visitors a second-half lead before a late penalty from Inigo Idiakez
Rasiak created an opening after 12 minutes and stabbed a close-range shot that Mike Pollitt blocked but Tudgay somehow missed an open goal with the point blank follow up and hit the post.
Three minutes later danger man Rasiak produced a clever turn to wrong foot the home defence but smashed his 15-yard effort wide.
Rotherham had the ball in the net through John Mullin but it was ruled out by an offside flag.
But in the 24th minute the home side shocked Derby when they went ahead from the penalty spot. A derby hand blocked Shaun Barker's header and Martin Butler scored from the spot.
It took Derby eight minutes to level when Rasiak swivelled cleverly to shake of a challenge from Phil Gilchrist and then angled his shot out of Pollit's reach.
The Polish star could have added a second three minutes before half time but Pollitt made a superb save from his first-time shot after Moren Bisgaard picked him out with a low cross.
And Pollitt had to produce another important stop seconds later from an Idiakez free-kick.
But Derby put the game beyond Rotherham two minutes into the second half when Tudgay headed in Tommy Smith's cross from the left.
Fifteen minutes from the end Idiakez snapped up Derby's third with a penalty after Gilchrist brought down Adam Bolder.