Manchester City sealed top spot in Group F after coming from behind to beat Hoffenheim 2-1, with Leroy Sane scoring twice.
Needing just a point to guarantee going through as group winners, City seemed to be suffering a hangover from their defeat at Chelsea on Saturday and fell behind to an Andrej Kramaric penalty (16).
However, Sane struck a stunning free-kick to level it up (45+1) before finishing a flowing counter-attack (61) after a clever pass by Raheem Sterling, who played 90 minutes just four days after suffering alleged racist abuse at Stamford Bridge.
The draw for the last 16 of the Champions League will be on December 17 in Nyon and City will face one of Atletico Madrid, Roma, Schalke or Ajax.
Hoffenheim had to win to have any chance of qualifying in a Europa League spot and they were in front on 16 minutes.
Aymeric Laporte bundled over Benjamin Hubner which allowed former Leicester City striker Kramaric to slide home from the spot.
City struggled to find their rhythm from open play but looked dangerous from set-pieces as Gabriel Jesus hit the post and Nicolas Otamendi smacked the woodwork with a glancing header.
Just as it looked like City were out of ideas before the break, the equaliser came via the boot of Sane, who curled a majestic effort from 30 yards into the top corner.
City improved after the break as the visitors began to tire. Sane squandered an amazing three-on-one chance after passing to Bernardo Silva rather than shooting.
The winner did come when Sane combined with Sterling and was more ruthless with this finish.
Phil Foden played 90 minutes and nearly capped a brilliant second-half performance with a left-foot volley that was tipped over the crossbar by Oliver Baumann.
Man of the match: Leroy Sane
You get the feeling that Sane is starting to hit top gear with his performance levels. He was a constant threat down the left, linking expertly with Sterling and Foden. His opening goal was a thing of beauty and he should have helped himself to more than just the double he managed. This kid could be one of the world's best in a few years.
Opta stats
- Pep Guardiola has led his side to first place in the Champions League group stages for the ninth time in 10 seasons.
- Hoffenheim have both scored and conceded in all 14 of their games in all European competitions.
- The average age of Manchester City's starting XI was 24 years and 95 days, the youngest for an English side in the Champions League since Manchester United against CFR Cluj in December 2012 (24y 54d).
- Hoffenheim are the first side to finish bottom of their Champions League group despite scoring 10+ goals since Olympiakos in 2002-03 (11 goals).
- Sane is the first German to score twice against German opponents in the Champions League since Carsten Jancker for Bayern Munich against Kaiserslautern in March 1999.
- Kramaric has scored in each of his last four games in the Champions League for Hoffenheim (5 goals).
What's next?
Manchester City are back in action on Saturday lunchtime against Everton, a game live on Sky Sports Premier League and Main Event.