Eden Hazard scored his first Real Madrid goal in eight months on Thursday as La Liga's leaders staged a dramatic comeback with 10 men to scrape past Elche in the Copa del Rey.
Madrid needed extra-time to win 2-1 at the Martinez Valero and were given a scare by Elche, whose Gonzalo Verdu gave them the lead in the 103rd minute, moments after Marcelo had been sent off.
The victory sends Real Madrid into the quarter-finals, where they join Real Sociedad, Mallorca, Rayo Vallecano, Cadiz, Valencia and Real Betis. Barcelona play Athletic Bilbao later on Thursday.
Hazard has been fit but still on the fringes of Carlo Ancelotti's team this season and even in this cup game, he started on the bench.
But the 31-year-old came on at the start of extra-time and he will hope his winner can be the beginning of a resurgence in the second half of the season.
Karim Benzema was rested while Thibaut Courtois was unavailable due to a private matter, meaning Luka Jovic and Andre Lunin were given rare chances for Madrid up front and in goal.
Fede Valverde and Edouard Camavinga started in midfield instead of Luka Modric and Casemiro, although the latter pair had to be called upon late in the second half.
Elche should have taken an early lead but Guido Carillo was guilty of a miss that will surely go down as one of the worst of the season. He looked certain to score from a yard out but, off balance, skewed his finish onto the crossbar.
The game became stretched in the second half but neither side could create a decisive chance.
Eden Hazard and Dani Ceballos were introduced for extra-time, the Belgian replacing Rodrygo. Casemiro shot wide after Vinicius Junior capitalised on a sloppy pass but it was Elche who made the breakthrough in the 102nd minute.
Madrid were caught upfield and the ball was slid through for Guido, who nicked it away from Marcelo and drew a touch from the defender as he squeezed through. Marcelo was the last man and the red card went into the air.
The punishment was doubled as Verdu struck the resulting free-kick into the wall before banging the rebound back towards goal. The ball darted off the foot of Ceballos, wrong-footing Lunin and spinning into the corner.
Madrid looked exhausted but kept coming. Modric and Casemiro were quickening the pace and it was the latter's pass that set up the equaliser, Ceballos shooting from the pull-back and this time it was Isco who was in the right place to divert in.
Now the visitors, even with 10 men, found an extra gear, sniffing a winner and Hazard delivered it. David Alaba's curving pass sent Hazard in behind and he took one touch to skip round Werner and another to curl a left-footed shot into the net.
Elche thought they had another at the end when Fidel drove in at the back post, but Verdu was adjudged to have hauled down Nacho Fernandez. Pera Milla was sent off for his protests.