Both teams had a player sent off in a wild meeting in Amsterdam, and the home side temporarily lifted itself into top billing when Dusan Tadic scored his second from the penalty spot after 82 minutes for a 2-1 lead. But the advantage quickly changed hands when Robert Lewandowski and Kingsley Coman netted on 87 and 90 minutes, respectively.
The drama wasn't over. Ajax bundled over on 95 minutes - Nicolas Tagliafico was prominently involved, but some sources credited Niklas Sule with an own goal - but couldn't nick another last-gasp tally to swap positions with Bayern.
Lewandowski began the scoring just 13 minutes into the affair. Ajax had most of the ball in the opening half, but Bayern were the outfit fashioning the best chances.
The meeting was leveled when a flowing passing move was finished by Donny van de Beek picking out Tadic for a tap-in. The quickfire dismissals of Ajax's Maximilian Wober (for an erratic challenge on Leon Goretzka) and Bayern veteran Thomas Muller (for a dangerous high boot on Tagliafico) then sent proceedings into a manic, fierce, and thrilling closing phase of four goals and desperate fouls.
Bayern and Ajax will learn who their round-of-16 opponents are when the draw is conducted in Nyon, Switzerland on Monday.