City made a disastrous start, with defending champions Bayern ripping through their defence and racing into a 2-0 lead through strikes from Thomas Muller in the fifth minute and Mario Gotze in the 12th, but the visitors subsequently staged a remarkable comeback.
David Silva reduced the deficit with a close-range finish in the 28th minute and City then scored two second-half goals in quick succession to complete an incredible turnaround, with Aleksandar Kolarov converting a 59th-minute penalty before James Milner finished coolly three minutes later.
Both sides had already qualified for the knockout stages ahead of the match, but Bayern had not yet been confirmed as group winners and a 4-2 victory for second-placed City would have been enough to see the Blues leapfrog their German hosts.
In the end, with substitute Alvaro Negredo being denied late on by Manuel Neuer, City fell just short, but certainly they have made a statement about their credentials as they head into the last 16 of the competition.
And reflecting on the display, Pellegrini - whose side next host table-topping Arsenal in the Barclays Premier League on Saturday - said: "I think it was a very important game for us.
"I said that Arsenal was a priority above this game, and I said it was very difficult to win here by three goals.
"But for our team it was a very important win because we felt we needed revenge for what happened in Manchester (when Bayern recorded a dominant 3-1 victory at City) because we played very bad.
"Winning here after being two goals behind is very good. I'm very happy."
Pellegrini appeared to suggest he had not realised City needed only a further goal to go through as group winners, which would - theoretically at least - have ensured them an easier last-16 draw.
When asked if he had not been tempted to bring striker Sergio Aguero off the bench with the score at 3-2, Pellegrini said: "I was tempted if we scored the fourth goal.
"It was important to be first in the group but not the most important.
"It was difficult to score two goals."
The starting line-up Pellegrini selected for this game showed that he had been preparing for it with the Arsenal match also in mind.
The Blues' first XI showed seven changes from last weekend's draw at Southampton, with Joe Hart, Joleon Lescott, Javi Garcia, Jesus Navas, Edin Dzeko, the fit-again Silva and Micah Richards - who came off with an injury after only 15 minutes - being brought into it.
The likes of Vincent Kompany, Richards' replacement Pablo Zabaleta, Aguero, Negredo and Samir Nasri dropped out, as well as the suspended Yaya Toure.
And Pellegrini added: "I thought there was the chance for players to demonstrate why they are in the squad, and this was important."