Pre-match talk had focused on the quadruple chances of Pep Guardiola's men, but they had to come from behind at the Etihad Stadium despite the Catalan naming a strong side, Aguero coming off the bench to settle it.
Bristol City – who dumped Manchester United out in the last round – refused to be cowed and Lee Johnson's high-flying Championship team matched the runaway Premier League leaders in an enthralling first half, with the visitors going into the interval ahead courtesy of Bobby Reid's penalty.
Manchester City's centre-back pairing were both at fault, Eliaquim Mangala losing possession and John Stones mistiming a tackle in the box on Reid, who picked himself up to convert from the spot.
After a lax first period the hosts were much brighter and got back on terms 10 minutes into the second half, Kevin De Bruyne beating Frank Fielding with a powerful shot after playing a one-two with Raheem Sterling.
Fielding made a string of saves to keep the sides level but the goalkeeper could not stop Aguero flicking home Bernardo Silva's cross in injury time to give his side a slender advantage, although the Robins will take heart from their display ahead of hosting the second leg in two weeks' time.
City unsurprisingly began on the front foot as Ilkay Gundogan hit an effort wide and Bernardo Silva's deflected shot looped over, but Bristol City did not look overawed.
Johnson's men called Claudio Bravo into action for the first time after 15 minutes, Joe Bryan firing at goal after a driving run but finding the goalkeeper equal to his strike.
Fielding blocked Leroy Sane's cross and then had to tip over a whipped De Bruyne curler as the underdogs gave the ball away deep in their own half.
Marlon Pack rifled a drive at Bravo after 32 minutes as the visitors continued to pose a threat.
And after Bailey Wright was perhaps fortunate not to concede a penalty when he appeared to drag down Stones, the second-tier side won a spot-kick of their own.
Stones dived in on Reid after Mangala gave the ball away to Josh Brownhill, the fouled forward tucking away confidently from 12 yards.
Manchester City almost equalised immediately only for Aden Flint to make a miraculous headed clearance from Sterling's goalbound lob.
Fielding rushed out to deny Sterling five minutes after the break, but the he could do little about the equalising goal.
Bravo started an attack that Bristol City never got close to stopping, captain De Bruyne slamming in an unstoppable finish after swapping passes with Sterling.
Sterling, playing as a central striker with Aguero named among the substitutes, turned De Bruyne's cross at Fielding before Guardiola sent for the Argentina international with 20 minutes remaining.
Silva's cross was perfectly floated for Aguero to flick a header past Fielding and complete the turnaround at the death.
Key Opta facts:
- Manchester City have reached the final of the League Cup on three of the previous four occasions when winning the semi-final first leg, with the exception being against Manchester United in 2009-10.
- The Citizens are unbeaten in their last 32 games in domestic competition (W26 D6), with their last loss coming against Arsenal in the FA Cup in April 2017.
- The last team from a lower division to lose a League Cup semi-final first leg against Premier League opposition, and still qualify for the final, was Birmingham City v Ipswich Town in 2000-01 (4-2 on aggregate).
- Bristol City have scored more goals than any other team in the League Cup in 2017-18, with 12 of their 17 coming against Premier League opposition.
- Three of Sergio Aguero’s five goals in the League Cup have been scored in semi-finals (also against West Ham in January 2014 and Everton in January 2016).