The Premier League title holders fell to a 2-1 loss at home to Lyon in their opening Group F game, representing a fourth consecutive defeat in the competition.
But on Tuesday they fought back from going a goal down inside the first minute to triumph 2-1, with Sergio Aguero and David Silva on target in Germany.
Silva grabbed the winner in the 87th minute, taking advantage of a miscue from Hoffenheim defender Stefan Posch to fire home.
Guardiola was full of praise for City's opponents, while expressing relief his side were able to come away with three points.
"After losing the first game it was so important we don't lose – the game was tight and in the end [we won]. To win in Germany is always so difficult," said City boss Guardiola.
"They 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."
The result provides City with a timely boost as they prepare for Sunday's visit to Liverpool, with both sides boasting unbeaten top-flight records this season.