Karim Benzema's goal in stoppage time rescued Real Madrid's long unbeaten run and saw them set a new Spanish record of 40 games without defeat as they drew 3-3 at Sevilla in the Copa del Rey.
The goal saw Zinedine Zidane's side surpass the previous record set by rivals Barcelona last season and, in the process, they progress to the quarterfinals with a 6-3 aggregate win.
Leading 3-0 from the first leg, it looked like Madrid would lose on the night as they went into the final quarter of an hour 3-1 behind at Ramon Sanchez Pizjuan.
A Danilo own goal gave Sevilla the halftime lead but a superb individual effort from Marco Asensio brought the visitors level early in the second half.
However, Stevan Jovetic quickly restored Sevilla's lead and Vicente Iborra extended it -- giving Sevilla hope of making it through.
Those hopes were soon extinguished by a Sergio Ramos penalty before substitute Benzema struck in the 93rd minute to ensure a place in history.
The two clubs meet again on Sunday at the Ramon Sanchez Pizjuan in a top-of-the-table clash in La Liga, and with that huge game on the horizon both managers made changes.
Cristiano Ronaldo was the most notable absentee while Real also rested the likes of Benzema, Isco, Luka Modric and Raphael Varane. Samir Nasri and Steven N'Zonzi did not start for Sevilla, who will look to move within a point of the league leaders with victory at the weekend.
Sevilla needed to start well to have any chance of overturning their first-leg deficit and they did just that. Joaquin Correa worked Kiko Casilla early on before a Danilo own goal put them right back in the tie after 10 minutes.
Pablo Sarabia's cross into the penalty area panicked Danilo who, charging towards his own goal, sent a bullet of a header past Casilla giving the goalkeeper no chance.
Asensio had a good chance to equalise straight away but his effort was straight at David Soria, who was then fortunate to see the ball ricochet wide after his clearance struck Mariano.
Mariano, who scored a hat-trick in the previous round, did have the ball in the net after half an hour but his strike was correctly ruled out for offside.
Back at the other end, Casilla twice kept Sevilla at bay with saves to deny Wissam Ben Yedder and Luciano Vietto to ensure Real went into the break just a goal behind on the night, and it proved vital as four minutes into the second half they were level.
Asensio picked up the ball deep inside his own half and embarked on a 60-yard gallop, forcing his way into the box before squeezing a shot beneath the goalkeeper.
That meant Sevilla needed four more goals to go through but they got one in the 55th minute when Jovetic marked his debut with a crisp back-post volley. The former Manchester City striker was denied another goal shortly afterwards by a fine block by Casilla.
Real twice came close to drawing level on the night midway through the second half when Alvaro Morata scooped a shot over the crossbar and Adil Rami was within inches of diverting the ball into his own net.
Jovetic made a difference with his introduction just before half-time, replacing the injured Correa, and the Montenegro international went close again after 77 minutes when he glanced a header narrowly wide from a corner.
It looked like Sevilla had set up a grandstand finish nine minutes from time when Casilla failed to hold a shot and Iborra tucked away the rebound. But with four minutes remaining Real scored again after Mateo Kovacic was brought down for a penalty.
Former Sevilla defender Ramos had been the target of much abuse on his return to the club he left over a decade ago, but he silenced the home fans with a Panenka spot kick.
While that was the end of the tie as a contest, it was not the last of the action as Clement Lenglet powered a header against a post with Casilla well beaten, before Benzema levelled things up on the night with a deflected shot, the final kick of the game.