Kevin McIntyre scored a late winner for Rochdale as Rotherham suffered their first defeat at their new home.
Veteran Dele Adebola fired into an empty net to give Rochdale the lead before Alex Revell levelled with a powerful header on the hour.
Daniel Nardiello nodded home from close range for the Millers before Bobby Grant equalised from the spot after Jason Kennedy was fouled in the area.
And McIntyre fired home from 25 yards to seal victory for Rochdale.
VIEWS FROM THE DRESSING ROOM
Rotherham United assistant manager Paul Raynor tells BBC Radio Sheffield:
"Our first half performance was way below par.
"We got a grip at half time, shook a few people up, made a couple of changes tactically and went ahead.
"We deserved to do that on the front foot and a bit of suicidal defending gave a free-kick away.
"When your 2-1 up, you can't concede three goals at home, that's for sure."