Match ends, FC Bayern München 2, Manchester City 3.
Manchester City staged a superb comeback to end Bayern Munich's record run of 10 consecutive Champions League wins but they still finished as Group D runners-up behind the German champions.
Bayern were dominant early on as Thomas Muller struck from Dante's pass before Mario Gotze scored following a corner.
David Silva pulled a goal back from close range after Jesus Navas's cross.
Aleksandar Kolarov equalised with a penalty after James Milner was tripped before Milner's fine finish won it.
It was an amazing turnaround from Manuel Pellegrini's side, who almost earned the 4-2 victory they needed to go through as group winners as Alvaro Negredo had a late effort saved by Bayern goalkeeper Manuel Neuer.
But after Bayern scored twice in the opening 12 minutes, the fact City fought back to claim an unexpected victory will give them confidence as they progress to the last 16 for the first time.
Although Bayern and City both finished with 15 points, the German side's 3-1 win during the first group game in Manchester meant their better goal difference proved crucial.
Both teams had already qualified before this game but Bayern boss Pep Guardiola was clear that finishing second in the group - and thus facing a seeded team in the first knockout round - was "not an option".
But his team looked vulnerable as they suffered only their third defeat of 2013 with Silva and Milner excellent throughout.
It started with the Germans in imperious form as City looked nervous after an early a mix-up between Joleon Lescott and recalled goalkeeper Joe Hart.
And after five minutes the visitors were undone as Dante's diagonal pass caught Kolarov napping and Muller nipped in behind the City captain to finish past Hart.
Hart had to save Dante's header and turned Ribery's effort onto the post after another Lescott mistake before Bayern went 2-0 up from the resulting corner.
Mario Mandzukic had time to shoot towards goal and his effort found Gotze, who also had space to stroke the ball past Hart from close-range.
By this stage, the only question was how many goals Bayern would score. Hart had made four touches, and two of them were to pick the ball out of the net.
Matters appeared to worsen when Micah Richards was replaced at right-back by Pablo Zabaleta after pulling a hamstring but the introduction of the experienced Argentine seemed to galvanise the visitors.
Shortly after a decent passage of play, City grabbed a goal back. Silva, on his return to the team after a calf injury, tucked in after Milner had headed Navas's right-wing centre back across goal.
After a frantic first half, City continued to improve but in the space of three minutes either side of the hour mark, the game then flipped on its head.
Silva was the architect as he played in Milner, who was brought down by Dante in the penalty area. Kolarov sent Neuer the wrong way from 12 yards.
Spanish midfielder Silva then set Navas free down the right and Milner curled a beautiful shot in at the back post after Bayern's Jerome Boateng had missed the cross,
Substitute Negredo could have made it a perfect night when Neuer saved his shot before Pellegrini chose to bring on Jack Rodwell instead of Sergio Aguero as they chased a fourth goal.
Whatever the group placings, this was an incredible way for City to flex their muscles before hosting Premier League leaders Arsenal on Saturday.
To see a gallery of images from today's Premier League games go to the BBC Sport Facebook page
- 6Thiago Alcántara
- 4Costa SantosBooked at 40mins
- 19GötzeSubstituted forMartínez Aguinagaat 55'minutes
- 9MandzukicSubstituted forShaqiriat 68'minutes
- 5van Buyten
- 8Martínez Aguinaga
- 13Ferreira de Souza
- 2RichardsSubstituted forZabaletaat 16'minutesBooked at 83mins
- 25FernandinhoBooked at 78mins
- 14García Fernández
- 10DzekoBooked at 42minsSubstituted forRodwellat 88'minutes
- 21SilvaSubstituted forNegredoat 73'minutes
- 7MilnerBooked at 44mins
- David Fernández Borbalán
- Shots on Target
Second Half ends, FC Bayern München 2, Manchester City 3.
Foul by Javi Martínez (FC Bayern München).
Fernandinho (Manchester City) wins a free kick in the defensive half.
Corner, FC Bayern München. Conceded by Pablo Zabaleta.
Philipp Lahm (FC Bayern München) wins a free kick in the defensive half.
Foul by James Milner (Manchester City).
Offside, Manchester City. James Milner tries a through ball, but Álvaro Negredo is caught offside.
Offside, FC Bayern München. Xherdan Shaqiri tries a through ball, but Dante is caught offside.
Corner, FC Bayern München. Conceded by Aleksandar Kolarov.
Substitution, Manchester City. Jack Rodwell replaces Edin Dzeko.
Offside, FC Bayern München. Thiago Alcántara tries a through ball, but Thomas Müller is caught offside.
Thiago Alcántara (FC Bayern München) wins a free kick in the defensive half.
Foul by Fernandinho (Manchester City).
Pablo Zabaleta (Manchester City) is shown the yellow card for a bad foul.
Franck Ribéry (FC Bayern München) wins a free kick on the left wing.
Foul by Pablo Zabaleta (Manchester City).
Attempt saved. Xherdan Shaqiri (FC Bayern München) left footed shot from outside the box is saved in the centre of the goal. Assisted by David Alaba.
Javi Martínez (FC Bayern München) wins a free kick on the right wing.
Foul by Edin Dzeko (Manchester City).