Rotherham’s Championship survival hopes suffered a blow after substitute Andreas Weimann fired a stoppage-time winner to secure Bristol City a 2-1 victory at Ashton Gate.
The home side took a 15th-minute lead when Cameron Pring delivered a high cross from the left and Tommy Conway rose to notch his 11th goal of the season with a header.
Rotherham were level in the 67th minute when Jordan Hugill sent Max O’Leary the wrong way with a penalty awarded for a foul on him by Zak Vyner.
But City had the final say at the death when Kal Naismith had a shot saved in a crowded box and Weimann pounced to shoot past Viktor Johansson from eight yards, leaving the Millers three points above the relegation zone.
Rotherham were almost caught cold inside the first 30 seconds of the game as Sam Bell burst into the box and saw his right-footed shot bring a diving save from Viktor Johansson.
Zak Vyner might have put City in front after 12 minutes, but fired over from Bell’s low cross.
Three minutes later Conway broke the deadlock from another build-up down the left where Pring and Bell were causing Rotherham plenty of problems.
Harry Cornick should have made it 2-0 in the 27th minute, somehow contriving to shoot over with the goal at his mercy a few yards out.
Bell’s pace was a constant threat, but when he went down inside the box under a challenge from behind by Cameron Humphreys, referee Josh Smith waved aside the penalty appeals.
Rotherham could not summon up a final pass to make the most of some promising situations and half-time arrived without City goalkeeper O’Leary having made a save.
Visiting boss Matt Taylor made a change for the start of the second half, with Richard Wood replacing Tyler Blackett in the centre of defence.
Two more Rotherham substitutions quickly followed, Wes Harding and Oliver Rathbone taking over from Lee Peltier and Conor Coventry.
Still City were looking the more dangerous side and Conway had a 60th-minute shot parried by Johansson.
Vyner’s initial poor touch led to him conceding the spot-kick which brought Rotherham’s equaliser. But it was a contentious decision and City boss Nigel Pearson was shown a yellow card for his protests.
The penalty proved to be Hugill’s last touch as he was immediately replaced by Georgie Kelly, who was just off target with a header shortly after going on.
Pearson sent on Weimann and Mark Sykes for Alex Scott and Cornick as his team raised the tempo in search of a winner.
It was Rotherham who almost snatched victory when their fourth substitute Shane Ferguson saw a well struck drive from distance come back off a post.
Then Kelly robbed City substitute Joe Williams, forcing a diving save from O’Leary, before Weimann’s winner had home fans on their feet.