Aguero scored from the penalty spot mid-way through the first half after Mehdi Benatia had been sent off, only for goals from birthday boy Xabi Alonso and Robert Lewandowski to put Bayern in front at half-time at the Etihad Stadium.
But a mistake from Alonso enabled Aguero to equalise in the 85th minute and six minutes later the Argentine exploited an error by City old boy Jerome Boateng to give Manuel Pellegrini’s side a dramatic victory.
City will now go into their final game away to Roma level on points with the Italian side and CSKA Moscow, meaning they will qualify if they win and the Russian champions fail to win at Bayern, who were already guaranteed to qualify as Group E winners.
With Yaya Toure and Fernandinho suspended, City lined up with Fernando, James Milner and Frank Lampard in midfield, while injury-hit Bayern handed starts to Sebastian Rode and 19-year-old Dane Pierre Hojbjerg.
Arjen Robben was quickly buzzing around the fringe of the City area and he created two early chances.
The Dutchman’s chipped pass obliged Joe Hart to save from Rode and he then teed up Rafinha for a shot that Eliaquim Mangala blocked.
Short of a couple of crosses from Jesus Navas that failed to find a sky blue shirt, City had created nothing, but without warning the game titled in their favour.
Lampard’s pass over the top freed Aguero, who raced into the box before being brought down from behind by the sliding Benatia.
Referee Pavel Kralovec showed the Morocco international a straight red card and although Bayern goalkeeper Manuel Neuer went the right way, Aguero’s penalty eluded him.
– Alonso equalises –
Visiting coach Pep Guardiola was forced into an unwelcome reshuffle, with Dante coming on for Rode, and Lampard almost extended City’s advantage by shooting narrowly high and wide from a smart free-kick routine.
But Bayern survived, regrouped, and by half-time they were ahead.
Alonso equalised in the 40th minute, crowning his 33rd birthday by steering a low free-kick past a flat-footed Hart after Mangala had upended Lewandowski.
Five minutes later, Lewandowski stole in front of Bacary Sagna to meet Boateng’s right-wing cross and although the ball made more contact with shoulder than head, it was enough to send it looping over Hart.
Alonso gave City a scare early in the second half by curling wide, but the home side began to press, with Neuer saving smartly from Navas’s low shot and James Milner curling over from the left.
With Pellegrini introducing striker Stevan Jovetic and right-back Pablo Zabaleta for the final stages, City continued to venture forward.
Neuer produced a flying one-handed save to thwart Lampard and Vincent Kompany scuffed wide from a corner, before Alonso’s cross-field pass was cut out by Jovetic, allowing Aguero to scuttle through and equalise.
The Etihad celebrated with wild abandon, but there was more to come.
In the first minute of injury time, Boateng’s poor touch let Aguero in and he held his nerve to beat Neuer, taking his goal tally for the season to 17 and giving City unexpected hope.