Pep Guardiola's side, who suffered a 2-1 loss at home to Lyon in their Group F opener, fell behind inside 44 seconds on Tuesday.
But the Premier League champions bounced back to end the longest losing streak of an English side in the competition's history.
And the turnaround was completed late on courtesy of David Silva's opportunistic strike just three minutes from time.
In the first meeting between the sides, the Bundesliga outfit wasted no time in forging ahead, Ishak Belfodil coolly converting following Kerem Demirbay's throughball.
But that stung the visitors into life and when Silva deftly picked out Leroy Sane, the former Schalke star squared for Aguero – who overcame a foot injury to retain his place – to tap home.
Raheem Sterling was denied by Oliver Baumann at the end of a strong run and Aguero volleyed over on the stretch after excellent trickery from Sane, with City piling on the pressure.
Baumann produced a stunning one-handed stop to thwart Aguero again before the break, but the hosts regained a foothold in the second half.
For the opening 25 minutes, Julian Nagelsmann's side contained City without managing to create much for themselves.
Sane had a strong shout for a penalty waved away when he took a tumble in the box after Baumann rushed out to meet him.
But City finally got the winner after Stefan Posch was caught dallying inside the area, allowing Silva to find the bottom-right corner with typical assuredness.
What does it mean: City's bid for European glory back on track
It may be a stretch to say the loss to Lyon had derailed City's bid for the most sought-after trophy in European football, but it certainly cast further doubts over their pedigree in this tournament. With this result, City will be feeling a lot brighter about their prospects.
Sane shines on home soil
It was an impressive showing from Sane, who had Hoffenheim running scared practically every time he got the ball. His attitude has at times been questioned, but his quality is not in doubt.
Away-day defensive woes return
The rude awakening City endured offered another timely reminder of their frailties in away Champions League matches. In their last 17 road trips in the competition, City have kept only two clean sheets. It is a tough enough trophy to win without starting every away game a goal down.
Key Opta facts
- Manchester City are unbeaten in their last six Champions League games against German opponents (W5 D1).
- Hoffenheim have won just one of their previous 10 matches in European competition (D3 L6).
- Sergio Aguero became just the second player to score in five consecutive away Champions League appearances for an English team after Ruud van Nistelrooy for Manchester United in 2003.
- Five of David Silva's six Champions League goals for City have come against German opposition.
Guardiola's side travel to Anfield for a mouth-watering clash with Jurgen Klopp's Liverpool on Sunday, with both sides unbeaten in the league this season. Hoffenheim, meanwhile, host Eintracht Frankfurt on the same day, seeking to climb the Bundesliga table after a sluggish start.