Trailing 2-1 heading into the final five minutes plus injury time, City were in desperate need of a hero at Eastlands - and familiar face Aguero was able to punish Bayern for being caught on the ball.
City forced turnovers for both goals, Aguero directly gaining possession from Bayern defender Jerome Boateng as the game ticked past 90 minutes before firing past Manuel Neuer to complete a hat-trick and breathe life into the club's knockout-stage hopes.
Guardiola said it was a lesson for his men, who had already sewed up top spot in Group E before their trip to Manchester.
"Even though we lost, I am very proud of my team," Guardiola said, as reported by UEFA.com.
"We played with 10 men for much of the game, despite that we continued to dominate possession and play an aggressive game.
"But that sort of thing happens in the Champions League, perhaps tonight is a big lesson for us.
"This is a group game, if it happens in the last 16 onwards then you are out of the competition."
Guardiola watched on as Mehdi Benatia's foul on Aguero inside 20 minutes saw City gain a numerical advantage, but his side fought back from a deficit to lead at half-time after a Xabi Alonso free-kick and a Robert Lewandowski header.
"We dominated, but we made two mistakes and that is why we lost," the Spaniard said.
"I'm sad for the players, they don't deserve this. Of course I have to congratulate City, they have the chance to go to the next stage.
"We will try to win against CSKA [in the final group game].
"This year I think we are better than we were last year because we have spent more time together.
"Last year we had short periods where we played good but not always. Now we know each other better."
Bayern defender Rafinha claimed fatigue was a factor in their two costly turnovers.
"It was a game we dominated for 75 minutes and then with individual mistakes we gave away two goals," the Brazilian said.
"At that stage we were tired, we had run a lot.
"We are pleased we played well but disappointed we lost. They were just two mistakes.
"The word is frustration, because we dominated the game even with a man less.
"We know we lost because of individual errors on our part, but we win and we lose as a group."
Get the best features, fun and footballing frolics straight to your inbox every week.