The Blues were a goal behind in less than one minute when Ishak Belfodil sprung the City offside trap to finish under goalkeeper Ederson.
City responded quickly, with David Silva‘s defence splitting pass allowing Leroy Sane to lay on the assist for Sergio Aguero.
At that point City looked well placed to score more, but a resilient Hoffenheim performance coupled with one strong penalty appeal for Leroy Sane turned down, meant it looked like the game was heading for a draw.
But in the 87th minute Silva’s brilliant reading of the play allowed him to pick-pocket the home defence and finish on the turn.
Although City’s fans were put through a tense night, Guardiola is convinced matches like this can galvanise a team for future success.
READ: Hoffenheim 1-2 City - match verdict
“After losing the first game it was so important we don’t lose today - the game was tight and in the end (we won),” Guardiola said.
“To win in Germany is always so complicated. It’s a good three points, we fought against a lot of things, and that is why satisfying for the team.”
He added: “They (Hoffenheim) are so well organised defensively, with the ball they are so strong. It was not easy to find it, but at end we found the right moment to win the game.
“We need to live this experience to get better. You cannot make the next steps if you don’t suffer, you don’t live this experience - so this will be good for the future.”
The boss confirmed City’s medics would check on Ilkay Gundogan on Wednesday after the Germany midfielder left the play clutching his hamstring in the second-half.