On a historic night for the club, City fought back from two-goals down to break the holders’ record 10-match Champions League winning streak as Bayern coach Pep Guardiola suffered his first defeat in major competition with the German side.
Bayern also had first home defeat — after 18 wins in Munich — since losing 2-0 at home to Arsenal in last season’s knock-out stages of the Champions League in March.
With both teams already through to the knock-out stages, City avenged October’s 3-1 defeat to Bayern at the Etihad Stadium, but still finished second to the Germans in Group D with both teams on 15 points.
City winger James Milner completed the fairytale fightback with the 62nd-minute winner, but a 4-2 win would have sent Pellegrini’s side through as Group D winners.
Pellegrini brought on Spanish striker Alvaro Negredo for David Silva, back from a calf injury, for the final 20 minutes, but the Chilean admitted his thinking had been as much about the Gunners as chasing a fourth goal.
“It was important for us to get the fourth goal, but it would also have been a risk of continuing playing with David Silva,” said the City coach.
“It was important for us to be at the top of the group, but we also have a big game on Saturday and it was not the most important thing.”
Remarkably, City pulled off a famous European victory at the defending champions with first-choice forwards Sergio Aguero and Negredo, plus captain Vincent Kompany started on the bench.
“It’s an important victory for the club, not just for me,” said Pellegrini, who later said on television that he was not aware a 4-2 win would have put City through as group winners.
“I have been trying to find a style of play here, some of our results had not been that good in the Premier League and this is very good for the club.
“The first message for the squad is that they can win without the likes of Kompany, Aguero and Negredo.
“I told they players this was the chance to prove to me what they can do, that is the most important thing for me.”
It had started ominously for City as Bayern raced into a 2-0 lead after 11 minutes.
Goals by Thomas Mueller and Mario Goetze left Bayern cruising before Silva pulled one back for City as it finished 2-1 at the break.
Stand-in captain Aleksandar Kolarov then converted a penalty to pull level on 59 minutes before Milner gave City a deserved lead three minutes later with a superb curling shot to complete the miraculous fight-back.
Despite his first major defeat, not including July’s pre-season German Super Cup defeat at Borussia Dortmund, Guardiola was in philosophical mood.
“Perhaps we needed a defeat to remind us of a few things,” said the Spaniard.
“We have made a good start in the league, in the cup, in the Champions League, winning in Manchester, perhaps we thought things were too easy.
“Congratulations to City, I also congratulated my players in the changing room for finishing top of their group. The most important thing now is that we learn the lessons from the defeat.
“It’s not a bad thing for us to lose, I read all the time how ‘Bayern will win their next game’ or ‘Bayern have it easy’.
“No, no, no, that’s not football. We had a lot of possession, but we must use the ball and counter attack more, we have to create more.”
This was only the second time Bayern have thrown away a two-goal lead in the Champions League having gone down 3-2 to AS Roma in November 2010.