The Millers, who trailed to Martyn Woolford’s early opener, recovered after the break and hit back through goals from Danny Ward and Kari Arnason.
Ward struck after just 73 seconds of the second period while Arnason headed home from a corner five minutes from time.
It meant Steve Evans’ side moved six points clear of Millwall, who occupy the final spot in the relegation zone, and led to ugly scenes in the away end at the AESSEAL New York Stadium as irate visiting supporters tried to invade the home areas, with riot police forced to intervene.
Rotherham, buoyed by some recent impressive home form, started well and put the Millwall penalty area under considerable pressure, with David Forde palming away Ben Pringle’s free-kick.
But the Millers’ vulnerability at the other end was highlighted as the Lions stole a 20th-minute lead when Shaun Williams’ cross was headed back across goal by Gary Taylor-Fletcher and Woolford’s looping volley beat Adam Collin.
The Millers’ response was good and they had a spell camped in their visitors’ half, going close on several occasions.
Matt Derbyshire twice headed off target, Danny Ward was inches away from meeting Jack Hunt’s cross and Richie Smallwood’s goalbound shot was blocked.
But Millwall had a superb chance to make to it 2-0 nine minutes before the break as Lee Gregory was allowed to get on the end of Ben Harding’s long punt down the field but his shot from close range was superbly kept out by Collin.
The Millers needed to up their game if they were to get anything out of the match and they responded by making a flying start to the second period, levelling inside 90 seconds.
Pringle’s deep cross was headed back across goal and Ward’s low volley from 12 yards caught a slight deflection and beat Forde.
That set the tone for the rest of the half as the hosts penned Millwall back and they were within inches of taking the lead in the 63rd minute when Hunt burst into the area but his fierce drive crashed in to a post with Ward’s effort from the rebound was palmed away by Forde.
The Millers pressure continued and it was eventually rewarded in the 85th minute when Arnason was left unmarked from Pringle’s corner and he headed home a vital winner.
The hosts were able to see it out, while angry Millwall fans, who chanted for the sacking of manager Ian Holloway, tried to invade the home section of supporters.