Striker Robert Lewandowski scored twice as Bayern Munich sealed top spot in Group E following a thrilling 3-3 Champions League draw at Ajax in which both sides ended with 10 men.
Ajax came from behind to lead through Dusan Tadic's double and looked set to claim top spot before a frenetic finale in which Bayern edged in front only for Nicolas Tagliafico to equalise for the hosts deep into stoppage time.
Lewandowski, who has now scored 21 goals in as many games in all competitions this season, grabbed an equaliser from the penalty-spot before Kingsley Coman struck what seemed an excellent late winner for the German side.
The hosts set up a thrilling finish when defender Tagliafico's effort ended up in the back of the Bayern net, but the visitors were able to see out the remaining seconds and go into the second round draw as one of the seeded sides.
Both teams finished the pool unbeaten with Bayern on 14 points to Ajax's 12, while Benfica ended in third with seven points after they claimed a 1-0 home victory over AEK Athens thanks to Alex Grimaldo's late winner.
Bayern led 1-0 at halftime thanks to Lewandowski's 13th minute goal, but the game came to life in an extraordinary second period.
Ajax levelled through Tadic before both sides were reduced to 10 men in separate incidents, with the home side's Austrian defender Maximilian Wober given a straight red card for a wild lunge and Bayern's Thomas Muller following him seven minutes later for another dangerous tackle.
Ajax looked like they might snatch top spot in the pool when Tadic put them ahead via the penalty spot, but that lead lasted only four minutes as Lewandowski also converted from the spot.
Coman netted with a fine strike from just inside the box as the game went into stoppage time, but there was still time for a desperate Ajax to find an equaliser as they poured players forward and Tagliafico tapped home Klaas-Jan Huntelaar's cross.