Adam Webster headed an 86th-minute winner to give Bristol City a 1-0 Championship win over a Rotherham side who finished with nine men.
The centre-back was on hand to nod home Jack Hunt's cross from the right, with goalkeeper Marek Rodak just failing to keep the ball out with a desperate dive.
Rotherham were reduced to 10 men in the 64th minute when full-back Billy Jones, booked 12 minutes earlier, was shown a second yellow card for pulling back Famara Diedhiou.
And that became nine men eight minutes later as Richie Towell leapt into a late challenge on Josh Brownhill in the centre of the pitch, earning a straight red from referee Scott Duncan.
The visitors showed tremendous resistance with their two-man disadvantage, but could not deny Lee Johnson's team extending their unbeaten run to seven games, with the Millers slipping into the relegation zone as a result.
Both sides squandered good chances in an open, entertaining first half. Rodak made the first save of note after 10 minutes, reacting smartly to keep out Diedhiou's near-post header from a Callum O'Dowda corner.
Jamie Paterson should have done better with a 13th-minute header that brought a comfortable save from Rodak, but soon Rotherham were showing attacking intent of their own.
Striker Michael Smith had a low 20th-minute shot saved by Niki Maenpaa, but the main threat from the visitors came in the shape of Jon Taylor, operating on the right.
He robbed Jay Dasilva only to shoot into the side-netting and in the 26th minute forced a low save from Maenpaa.
Taylor had two other opportunities before the half-time whistle, having a fierce shot parried by Maenpaa and volleying just wide after a weak punch from the City keeper.
At the other end Paterson had a volley blocked and claims for a penalty when Diedhiou's header appeared to strike the arm of a Rotherham defender were waved aside by referee Duncan.
The second half soon followed the pattern of the first, with both teams hungry to attack, while lacking the finishing power to break the deadlock.
Then came the two dismissals and, with home fans roaring them on, City mounted wave after wave of attacks, only to be frustrated by some committed last-ditch defending.
Webster finally broke Rotherham's resistance and after the goal the home side went close to extending their advantage on several occasions.
Brownhill hit the crossbar, Rodak made a fine save to deny Paterson and substitute Andreas Weimann fired over when he should have scored.