Mateo Kovacic denied Legia Warsaw a famous Champions League victory, but holders Real Madrid still have work to do to reach the last 16 after a remarkable 3-3 draw.
Gareth Bale scored Madrid's fastest Champions League goal after 57 seconds with a magnificent long-range volley in a contest played behind closed doors at the Polish Army Stadium due to crowd trouble during Legia's home match with Borussia Dortmund in September.
And when Karim Benzema doubled the lead it looked as if Madrid would ease to a place in the knockout stages.
Despite a lack of any home advantage, Legia displayed impressive resiliency and produced an incredible turnaround to lead 3-2.
Vadis Odjidja-Ofoe pulled one back five minutes before half-time, with Miroslav Radovic then firing into the bottom-right corner to level matters in the 58th minute.
And the sparse crowd of club officials in attendance looked set to witness one of the biggest shocks in Champions League history when Thibault Moulin curled in off the post for Legia's third, only for Kovacic to cap off a neat Madrid move and ensure a share of the spoils with five minutes left.
The draw means Madrid are now two points behind Group F leaders Borussia Dortmund and five ahead of Sporting CP. Meanwhile, Legia can no longer progress, but still harbour hope of a Europa League place.
Bale needed little time to make his mark, capitalising after Legia failed to clear their lines by lashing a wondrous volley into the top-right corner.
Madrid unsurprisingly continued to dictate proceedings and Raphael Varane went agonisingly close to making it 2-0 as his header was cleared off the line before Benzema drew a fine save from Arkadiusz Malarz.
Malarz was called into action again when Bale's header from a near-post corner forced the Legia goalkeeper to produce an excellent finger-tip stop, with Benzema and Cristiano Ronaldo unable to force home the rebound.
Bale then had Malarz scrambling again with a vicious drive from the edge of the area that dipped just over the crossbar.
But the second goal finally arrived in the 35th minute, with Bale involved again as he latched onto Kovacic's clever pass and laid the ball off for Benzema to slot into the bottom-right corner.
However, the two-goal advantage was halved just five minutes later, Odjidja-Ofoe weaving his way to the edge of the area and curling a left-footed strike beyond Keylor Navas.
A bright start to the second half saw a Bale near-post volley kept out by Malarz and Ronaldo fire into the side-netting, with Legia midfielder Guilherme then bending a free-kick narrowly off target at the other end.
But Radovic did make Madrid pay for not extending their lead, finding the net with a low drive from just outside the box after being afforded too much space by the visitors' defence.
Benezma went close to restoring Madrid's advantage as he had an effort deflected narrowly wide by Adam Hlousek before Ronaldo sent a header past the right-hand post.
Ronaldo looked in the mood to settle matters, testing Malarz with a free-kick and looping a header over, but instead it was Moulin who seemed to have clinched an unbelievable result by meeting Aleksandar Prijovic's lay-off with a superb strike with seven minutes left.
There was a final twist in the tale, though, and it came as Kovacic met Dani Carvajal's flick with a confident angled finish, with the woodwork denying Madrid a last-gasp win when Lucas Vazquez rattled the bar.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.