Milner benefited from an error by former City man Jerome Boateng, who failed to clear a Jesus Navas cross on 62 minutes. Milner sent the shot spinning into the corner of the net with Manuel Neuer beaten to ensure the visitors of the three points on the night.
Both teams finish Group D with 15 points from six matches, but Bayern edged the Premier League side for top spot courtesy of their 3-1 in Manchester back in October.
City looked like they were set to encounter a serious going over when Thomas Mueller and Mario Goetze benefited from some wretched defending to give Bayern a 2-0 lead in the opening 12 minutes.
With Bayern looking strangely subdued, Aleksandar Kolarov planted a penalty into the corner of the net with Neuer sent the wrong way from the spot on 59 minutes after Dante had felled Milner in the area.
Milner would soon become the first English player to score in the Champions League for City with his decisive goal. The draw for the knock-out stages of the last 16 takes place on Friday.
'5 - MUELLER OPENER: Mueller drives the ball into the corner of the net. Hart left well beaten. Aleksandar Kolarov caught on his heels. A 1-0 lead for Bayern.
'11 - RIBERY HITS BAR: Ball breaks to Ribery in the City box, but the ball spins off Hart before coming off the bar. City all over the place. A corner here to Bayern.
12' - GOETZE GRABS SECOND: Goetze slides the ball into the net. Awful defending by the visiting side as Mario Mandzukic was allowed to control the corner before his effort broke to the unmarked Goetze.
28' - SILVA GIVES CITY HOPE: Silva knocks the ball into the net from the Milner header back across goal. Fine cross by Navas. City back in the match at 2-1 behind.
59' - KOLAROV EQUALISER: GOAL! Kolarov plants the ball to Neuer's left, the Bayern goalkeeper flew right. City are level at 2-2. All to play for in Munich.
62' - MILNER MAGIC: Milner slides the ball into the corner of the net. Brilliant finish from Milner. Boateng all over the place from the Navas cross.
80' - DREADFUL DANTE: Dante almost lets in Negredo for a fourth City goal, but solid stop by Neuer. Shambolic stuff from Dante at the back. Not sure what he was trying there
Manchester City have won all three of their away Champions League matches this season; having lost five of their previous six (W1).
Bayern Munich had conceded just three goals in their previous 10 Champions League matches before tonight.
Bayern Munich lost a Champions League home match having held a two-goal lead for the first time in the competition's history.
Bayern Munich tasted defeat for the first time since their opening match of the season - a 4-2 Super Cup defeat to Borussia Dortmund back in July.
Manuel Pellegrini enjoys a victory over Josep Guardiola for the first time in 10 attempts.
TALKING POINT: Did Pellegrini make a blunder by not throwing on Sergio Aguero late on? Wasn't too clear, but the Manchester City coach seemed to suggest his side needed two more goals from leading 3-2 to progress as Group D winners when a 4-2 success would have given City the edge on the head-to-head with Bayern. Aguero could surely have been given the final 10 minutes or so rather than Jack Rodwell. The error in failing to field his side's leading striker will only become clear if City land Real Madrid or PSG in the last 16.
MAN OF THE MATCH
James Milner (Manchester City): A very underrated player for club and country, Milner struck the winner and had a hand in all three City goals. A terrific recovery from City. They should take huge heart, but Milner more than most should feel happy about his evening.
Bayern Munich: Neuer 6; Lahm 7, Boateng 7, Dante 4, Alaba 5; Thiago 5, Kroos 5; Muller 6, Gotze 6, Ribery 6, Mandzukic 6..subs: Martinez 6 Shaqiri 6
Manchester City: Hart 7, Kolarov 7, Lescott 7, Demichelis 7, Richards 5, Fernandinho 6, Garcia 6, Milner 8, Silva 7, Navas 7, Dzeko 7..subs: Zabaleta 8, Negredo 6, Rodwell 6
THE MATCH IN A TWEET