Substitute Sergio Aguero struck late to give Manchester City a 2-1 lead over Bristol City in the first leg of their Carabao Cup semi-final.
Bobby Reid put the Robins ahead with a penalty in the 44th minute, while Kevin De Bruyne hit back for Man City in the second half.
Lee Johnson’s side were dominated at times on Tuesday night, but it looked as if they would hold out for the draw until Aguero’s header in stoppage time.
It was a heartbreaking moment for Bristol City, but they are still very much in the tie ahead of the second leg at Ashton Gate in two weeks.
Naturally, it was Man City who dominated proceedings in the first half but some wasteful play in the final third, particularly from the rusty-looking Bernardo Silva, prevented them from taking the lead.
De Bruyne also had a couple of efforts from the edge of the area, but Frank Fielding was equal to both in the Bristol City goal.
And Man City would pay the penalty, literally, for their lacklustre finishing a couple of minutes before half-time. Eliaquim Mangala was the guilty man initially, giving the ball away to Josh Brownhill inside his own half.
The Bristol City midfielder took full advantage as he fed Reid into the box, and he surged forward before being chopped down by John Stones as he tried to cover for his defensive partner. The striker then stepped up to slot the resulting spot-kick past Claudio Bravo.
Man City would have equalised immediately were it not for the brilliant defensive work of Aden Flint, who managed to get back onto his line and head clear Raheem Sterling’s dinked effort that had already beaten Fielding and was destined for goal.
The home side did find the equaliser after 55 minutes when De Bruyne picked up a clearance from Bravo, turned and charged deep into Bristol City territory, then played a one-two with Sterling before sweeping the ball home from just inside the box.
Pep Guardiola threw on Aguero in search of the goal that would put them in control of the tie, and he eventually proved the difference in the second minute of stoppage time as he slipped away from his marker to head home a Silva cross from close range.