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."
Rotherham 01 Shearer 02 Tonge 05 Sharps 18 Hunt Booked (Agard - 82' ) 20 Morgan 08 Taylor 10 O'Connor 11 Evans (Ainsworth - 46' ) 15 Pringle 09 Revell 16 Odejayi (Nardiello - 56' ) Substitutes 21 Warrington 06 Mullins 07 Ainsworth 14 Bradley 24 Rose 17 Nardiello 22 Agard Rochdale 01 Lillis 02 Rafferty 03 Bennett 05 R Edwards 12 P Edwards Booked 14 McIntyre 07 Kennedy 08 Tutte 09 Donnelly 15 Adebola (Putterill - 62' ) 22 Grant Substitutes 31 Smith 19 Pearson 06 Barry-Murphy 11 Grimes 13 Putterill 23 Craney 20 Curran
Ref: Steve Martin