Semi Ajayi's header deep into injury time gave Rotherham a 2-1 victory at QPR for their first Sky Bet Championship away win of the season.
Ajayi put the Millers ahead with 20 minutes remaining but Bright Osayi-Samuel's 85th-minute equaliser appeared to have rescued a point for struggling Rangers.
However, Ajayi rose to meet Anthony Forde's left-wing free-kick with seconds remaining.
It was the Nigerian's fifth goal in four games and took third-from-bottom Rotherham level on points with Wigan and Reading.
The result also dragged QPR into serious trouble. Steve McClaren's side have lost nine of their past 11 Championship matches, have won just once in the league since Boxing Day, and are now seven points above the relegation zone.
A poor game finally came to life when Ajayi opened the scoring in emphatic fashion. Joe Newell's shot was blocked by defender Toni Leistner and Ajayi pounced on the loose ball and rifled a right-footed shot beyond keeper Joe Lumley and into the far corner of the net.
Rangers hit back when Jake Bidwell played the ball down the left to substitute Pawel Wszolek who cut it back for Osayi-Samuel to score from close range.
QPR created most of the few chances the game produced before Ajayi emphatically broke the deadlock.
Tomer Hemed had two opportunities to give them the lead in the first half. Massimo Luongo's ball in from the left found its way to the on-loan Brighton striker via a slight touch off the head of Luke Freeman but keeper Marek Rodak saved with his legs to deny Hemed at point-blank range.
Hemed was then guilty of a bad miss when he headed over from Freeman's right-wing free-kick.
Rangers continued to stutter after the interval with Ebere Eze sending a weak effort wide of Rodak's near post and Osayi-Samuel shooting over after being put through by Leistner.
Having been on the back foot for most of the game, Rotherham should have gone ahead when an unmarked Michael Smith headed wide from Newell's cross from eight yards out.
But Ajayi made no mistake with his two chances to give his side three priceless points in the battle for survival, a battle which QPR are now very much a part of.