Sergio Aguero scored an injury-time winner as Manchester City came from behind to beat Bristol City in the Carabao Cup semi-final first leg.
The Championship side were excellent, especially in the first half, and led from Bobby Reid's penalty, awarded after John Stones chopped down the Robins player.
But Kevin de Bruyne equalised for the unbeaten Premier League leaders after a one-two with Raheem Sterling.
And as the underdogs looked set to take a draw and an away goal back to Bristol for the second leg, substitute Aguero headed in Bernardo Silva's cross.
But Bristol City - who knocked out their hosts' neighbours Manchester United in the previous round - produced a performance that will give them encouragement for the return at Ashton Gate on Tuesday, 23 January (19:45 GMT).
Lee Johnson's Bristol City have had a season to remember. As well as challenging for promotion to the top flight, they have beaten four Premier League sides on their run to the last four - Watford, Stoke, Crystal Palace and famously United in the quarter-finals.
Impressively in a season where many Premier League sides have adopted defensive tactics against Manchester City, who are yet to lose a domestic game all season, the Robins played some brave, risky attacking football.
Joe Bryan had a shot saved by Claudio Bravo at his near post and then Marlon Pack's 20-yard shot from Oleksandr Zinchenko's clearance was straight at the keeper.
They deserved to lead when Josh Brownhill won the ball off Eliaquim Mangala and played in Reid, who was brought down by Stones' mistimed tackle.
The Robins were more subdued in the second half, but almost scored a famous winner when debutant Liam Walsh fired wide from the corner of the box late on. And he was made to regret that miss all the more when Aguero popped up seconds from the end.
Pep Guardiola's side are still in contention for four trophies this season, with the Premier League looking all but won given their 15-point lead over Manchester United.
The Catalan named a strong line-up, although he started with no recognised striker and Sterling playing centrally. And for the second time in three days his side came back from 1-0 down to win, having knocked Burnley out of the FA Cup 4-1 on Saturday.
Their early attempts were kept out by solid Robins defending, although they almost led when De Bruyne's shot was tipped over by keeper Frank Fielding.
Then, after Mangala and Stones were both at fault for the visitors' converted penalty, the hosts thought they had levelled only for Sterling's chip over Fielding to be sensationally headed off the goalline by Aden Flint.
But Manchester City have demonstrated a fierce will to win this season and they kept pushing for a goal that eventually came from De Bruyne.
The move started with goalkeeper Bravo, who played the ball to the Belgian near the halfway line. De Bruyne charged towards the box and found Sterling, who played a first-time pass back to the playmaker to belt the ball home from 16 yards out.
As so often this season, Manchester City found a last-minute goal when they needed it, Aguero heading in Silva's cross from close range.
The champions elect are now unbeaten in 33 domestic games, a run stretching back to April.