The Millers went into the match at home to Brentford six points adrift of safety, but goals from Matt Derbyshire and Danny Ward secured a 2-1 win.
Defeat for MK Dons means the gap is now down to three.
With players returning from injury or making their first starts in a long while, Rotherham needed to get their noses in front and they duly did after 29 minutes.
Lee Frecklington fed Derbyshire from the right at the second attempt and the recalled striker directed the ball across goal and beyond visiting keeper David Button.
But there was uproar at AESSEAL New York Stadium in the 43rd minute when referee Mark Brown awarded Brentford a penalty.
Frecklington looked to have clearly won the ball only for Brown, who had been wretched from the first whistle, to decide Sergi Canos's tumble was worthy of a spot-kick.
Alan Judge's shot was saved by Lee Camp but the Bees man put away the rebound.
The Millers dominated the second half, creating several chances, and claimed the second goal they deserved in the 71st minute when Frecklington battled hard at a corner and the ball fell for substitute Danny Ward to fire home.
Camp pulled off a last-minute from Lasse Vibe to secure a well-merited and potentially priceless victory for the Millers.
Boss Neil Warnock had said beforehand the time was coming when he might have to gamble in Rothrham's hour of need.on players who weren't fully fit
Striker Leon Best, after two substitute appearances following groin surgery, was given a start and midfielder Frecklington, out since January 2 with hamstring and groin problems, was also in the side.
Also starting was left winger Jerome Thomas, signed as a free agent last week, who last began a match, for Premier League Crystal Palace, 13 months ago.
All three played a significant part in a stirring victory which brought fans at New York to their feet at the final whistle and put Warnock's men right back in the mix.
Rotherham United (4-4-2): Camp; Richardson, Broadfoot, Wood, Mattock; Halford, Frecklington (Green 81), Smallwood, Thomas (G Ward 76); Best (D Ward 64), Derbyshire. Subs not used: Kenny, Kelly, Newell, Clarke-Harris.
Brentford (4-2-3-1): Button; Yannaris, Dean, O'Connell, Bidwell; Woods, McEachran (Kerschbaumer 78); Canos (Vibe 83), Judge, Swift; Djuricin (Hofmann 64). Subs not used: Bonham, Saunders, Barbet, Clarke.
Goals: Derbyshire 29, D Ward 71 (Rotherham); Judge 43 (Brentford).
Referee: Mark Brown (East Yorkshire).
Attendance: 8,534 (556).