Skipper Ryan Cresswell headed home Exodus Geohaghon's long throw in the 93rd minute to seal a dramatic but deserved win over ten man Stanley who had led twice.
Cresswell returned to the side after a three game lay off following his grandad's death in place of Nick Fenton, but it was the home side who started brightly and opened the scoring on 9 minutes.
Andy Parkinson took advantage of Andy Warrington's hesitancy to round the 'keeper and slot the ball cooly into the net.
But the Millers replied just 7 minutes later as Adam Le Fondre raced through on goal after latching onto Cresswell's header, only to be pulled down by Kevin Long in the box.
The loanee was given his marching orders and Le Fondre despatched the spot kick to level proceedings.
The Millers then pressed to make their numerical advantage tell but Ian Dunbavin was at his best to thwart Kevin Ellison twice before the break, as a Le Fondre volley was also cleared off the line as the home side hung on.
However, they countered after the break and went infront once more on 49 minutes as Jimmy Ryan worked a neat corner with Shaun McConville to fire past Warrington from 20 yards.
The game then turned ugly with several seperate niggling incidents involving Stanley players, Geohaghon and Tom Pope before order was restored.
Le Fondre then headed in at the far post to seemingly equalise, only for the goal to be ruled out by the linesmans flag but in the final ten minutes the Millers got their rewards.
With 9 minutes to play, Nicky Law's right wing corner was met by Geohaghon at the back post who headed down into the corner to make it 2 apiece before sub Ryan Taylor's looping header thudded back off the upright on 85 minutes.
Cresswell then fittingly capped his return with the winner infront of the Millers fans, who spilled onto the pitch in celebration as his bullet header sealed victory.