Bradford City boosted their promotion ambitions with two quick-fire goals in a crazy five-minute spell.
Stuart McCall's side looked as though they would have to settle for a point after Rotherham had the best of the chances.
But then Luke O'Brien produced a blistering solo goal to give City a 71st minute lead.
Four minutes later, City keeper Rhys Evans made an amazing save as Rotherham came within a whisker of leveling, but then Nicky Law grabbed City's second to put the game beyond the home side.
Rotherham, whose leaky defence shipped nine goals in their last three outings, reshaped as manager Mark Robins looked to plug the gaps.
He drafted in Fulham keeper David Stockdale after bringing him in on a month's loan to cover for absentee Andy Warrington.
And it was Stockdale who denied City the lead before half-time when the visitors went closest to breaking the deadlock despite the home side's early domination.
City, boasting an impressive start to the season, had been pinned back but broke out thanks to a surging run from O'Brien that was a warning for Rotherham,
He cut in from the left and as the home side backed off he produced raking goalbound shot that deflected and could have caught out Stockdale, but the 23-year-old produced and excellent full-stretch save to turn round the effort.
After the break, Rotherham should have gone in front but Nick Fenton's towering header went over after a corner from Peter Holmes.
And when Dale Tonge cut in cleverly from the left, he drove a fierce shot over before Drewe Broughton headed over after Marc Joseph tossed a dangerous ball into the area.
But then O'Brien broke out and sprinted down the left, swept inside unchallenged and lashed a low shot to beat Stockdale.
Stunned Rotherham looked for a response and when Joseph headed into the six-yard box Broughton looked certain to head in, but Evans tipped it onto the underside of the bar and it was cleared.
City made another lightning break and this time it was Law whose shot was misjudged by Stockdale for City's emphatic second.