Match ends, Queens Park Rangers 1, Rotherham United 2.
Semi Ajayi's stoppage-time goal gave Rotherham their first win away win in the Championship this season at QPR.
Ajayi opened the scoring with a stunning strike from 25 yards which fizzed beyond R's goalkeeper Joe Lumley in the 71st minute.
The hosts equalised 14 minutes later as Bright Osayi-Samuel slotted the ball past Millers goalkeeper Marek Rodak.
But Ajayi scored Rotherham's winner in the 95th minute as he headed in Anthony Forde's free-kick to give his side their first victory over QPR for 68 years.
With relegation rivals Millwall winning 2-0 at Birmingham City, Rotherham looked to be falling out of touch with safety before Ajayi's late winner for a first away league win at the 19th attempt.
But the result sees Rotherham remain in the relegation zone on goal-difference, while QPR stay in 18th, seven points above the drop.
Rangers - who had scored just once in their last four Championship matches - nearly opened the scoring after nine minutes, but Rodak did well to keep out Tomer Hemed's header from Massimo Luongo's wicked cross.
The visitors could have led shortly after half-time but Michael Ihiekwe could not adjust his feet to turn in Richard Wood's header across goal.
QPR boss Steve McClaren told BBC Radio London:
"It was a big disappointment, to lose the game with the last kick - we've had that a few times and been kicked in the teeth and we've got to recover again.
"I thought we were poor tonight, we competed but gave away too many free-kicks in bad areas and they're very strong on that and it was our downfall. I thought we'd rescued a point but we didn't play enough football, create enough chances and the confidence looked low.
"That was disappointing because we played Leeds here two weeks ago and won the game with a great performance all round. Since then we've been poor and we need to address the situation."
Rotherham manager Paul Warne told BBC Radio Sheffield:
"It's pretty amazing to be honest. I won't underestimate how much it means to me and the dressing room and all the travelling fans.
"It was a big game for us and we knew we had to come away with something.
"To take the lead and then to give it away, I thought it was going to end up being horrendous. But we were much better second half than we were first half.
"It was a really edgy game, but for us to come here and nick a goal really late on, it really means a lot. It's important for us to pick up points and the winner was a really special moment."
- 2FurlongBooked at 90mins
- 3BidwellBooked at 43mins
- 8CousinsSubstituted forShodipoat 72'minutes
- 10EzeSubstituted forWszolekat 80'minutes
- 16HemedSubstituted forWellsat 72'minutes
- 3MattockBooked at 17mins
- 13TowellSubstituted forCrooksat 64'minutes
- 25WilesSubstituted forJonesat 90+2'minutes
- 22NewellSubstituted forFordeat 83'minutes
- David Webb
- Shots on Target
Second Half ends, Queens Park Rangers 1, Rotherham United 2.
Goal! Queens Park Rangers 1, Rotherham United 2. Semi Ajayi (Rotherham United) header from the centre of the box to the bottom left corner. Assisted by Anthony Forde with a cross following a set piece situation.
Darnell Furlong (Queens Park Rangers) is shown the yellow card for a bad foul.
Foul by Darnell Furlong (Queens Park Rangers).
Anthony Forde (Rotherham United) wins a free kick in the attacking half.
Substitution, Rotherham United. Billy Jones replaces Ben Wiles.
Corner, Queens Park Rangers. Conceded by Richard Wood.
Attempt missed. Anthony Forde (Rotherham United) right footed shot from outside the box is too high. Assisted by Matt Crooks.
Goal! Queens Park Rangers 1, Rotherham United 1. Bright Samuel (Queens Park Rangers) right footed shot from the centre of the box to the centre of the goal. Assisted by Nahki Wells.
Substitution, Rotherham United. Anthony Forde replaces Joe Newell.
Delay over. They are ready to continue.
Delay in match Joe Newell (Rotherham United) because of an injury.
Substitution, Queens Park Rangers. Pawel Wszolek replaces Eberechi Eze.
Joel Lynch (Queens Park Rangers) wins a free kick in the defensive half.
Foul by Michael Smith (Rotherham United).
Nahki Wells (Queens Park Rangers) hits the left post with a right footed shot from the centre of the box. Assisted by Jake Bidwell.
Corner, Queens Park Rangers. Conceded by Michael Ihiekwe.
Corner, Rotherham United. Conceded by Massimo Luongo.
Corner, Rotherham United. Conceded by Darnell Furlong.