Substitute Marco Reus scored a dramatic equaliser with two minutes remaining as Borussia Dortmund drew 2-2 at Real Madrid to claim top spot in Champions League Group F.
Karim Benzema reached 50 Champions League goals with a close-range finish and a header either side of half time – a double that appeared to set Madrid on the path to victory.
But Pierre-Emerick Aubameyang struck with his 19th goal of the season to give the visitors hope before Benzema was denied a hat-trick when hero of the night Reus cleared his header off the line.
Cristiano Ronaldo hit the post in the closing stages but Madrid paid the price for their profligacy when Reus converted Aubameyang's pass in the final moments.
Therefore it is Madrid who will have to face a group winner in the last 16, with Arsenal and Juventus among their potential opponents.
Andre Schurrle – starting as one of three Dortmund changes – shot over early on, but it was Madrid who made the stronger start and created a string of chances.
First, Ronaldo's flick fed Benzema and his left-footed strike was well kept out by Roman Weidenfeller.
The Portugal international then set up James Rodriguez, who was denied by Weidenfeller from close-range before the Colombia international – in as one of two Madrid switches – tested the goalkeeper with another effort.
The breakthrough looked likely and it arrived after 28 minutes. Dani Carvajal was wide open as Dortmund's defence allowed him to make ground down the right, and the defender's low cross was perfect for Benzema to take in his stride and convert from six yards.
Keylor Navas saved from Christian Pulisic as the visitors improved later in the half, before he made an even better stop to push Schurrle's free-kick past the post after it had found a way through the wall.
Dortmund threatened early after the break when Ousmane Dembele stabbed an effort narrowly wide after an impressive run, while Gonzalo Castro miscued a wonderful opportunity following a cutback from Pulisic.
But those misses proved costly when Benzema struck again on 53 minutes, heading in from eight yards from another excellent delivery, this time from James.
That was not the end of the match as a contest, though, with Aubameyang finishing coolly from six yards after captain Marcel Schmelzer had squared Julian Weigl's throughball into his path.
Thomas Tuchel brought on Reus and Emre Mor in an attempt to complete the comeback, while Madrid welcomed Toni Kroos back from injury for his first appearance in a month.
An entertaining contest continued when Ronaldo's effort was brilliantly saved by Weidenfeller, with Benzema denied a hat-trick from the resulting corner when his header was cleared off the line by Reus.
Marcelo blazed over a presentable chance after a swift Madrid counterattack, while Ronaldo somehow failed to net his 500th club goal when he struck the foot of the post after Lucas Vazquez's pass had found him wide open in the area.
And Madrid, who are still yet to suffer defeat this season, paid the price for failing to put the result beyond doubt in dramatic fashion.
Aubameyang latched on to Mor's pass and raced clear on the right to square for the onrushing Reus, the Germany international making no mistake with his high finish to stun the Santiago Bernabeu.