Both teams had already qualified for the knockout stage before the match, which was their concluding Group D fixture, but leaders Bayern had not yet been confirmed as winners of the section.
And a 4-2 triumph for second-placed City was one of the outcomes that would have been enough to see them leapfrog their German hosts, ensuring - theoretically at least - an easier last-16 draw for the Blues.
When defending champions Bayern raced into a 2-0 lead through strikes from Thomas Muller in the fifth minute and Mario Gotze in the 12th, it seemed simply a case of how many they would win by.
But David Silva reduced the deficit with a close-range effort in the 28th minute and the fightback continued as City then scored two second-half goals in quick succession, with Aleksandar Kolarov converting a 59th-minute penalty before James Milner finished coolly three minutes later.
Pellegrini declared himself "very happy" after the game, but when asked if he had not been tempted to bring Sergio Aguero, City's top scorer, off the bench when it was 3-2, he said: ''I was tempted if we scored the fourth goal, of course - that is why I sent Aguero to warm up.
"For our team, it is very important to be first in the group, but not the most important thing.
''It was difficult to score two (more) goals."
And midfielder Milner - who, as well as scoring, teed up Silva for his goal and won the penalty - said: "We didn't know if 4-2 would be enough or if we would need 5-2.
"We thought it needed to be 5-2 to be honest."
Reflecting on his side's effort overall, Pellegrini said: "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).
''Winning here after being two goals behind is very good. I'm very happy.''
The starting line-up Pellegrini named for the contest reflected that he had been preparing for it with Saturday's Barclays Premier League home match against Arsenal also in mind, showing seven changes from the draw at Southampton.
For Bayern, meanwhile, there were just two alterations from their 7-0 win at Werder Bremen, and the way they capitulated - particularly after looking so potent so early on - came as a considerable surprise.
"I hope we can see how difficult it is playing in Europe," their coach Pep Guardiola said.
"Sometimes things like this can happen and today it happened to us.
"That's our message for today - we have to learn our lessons from this."