Marco Asensio scored a last-minute winner as a much-changed Real Madrid side won at Leganes in the first leg of their Copa del Rey quarter-final tie.
Real Madrid were without the rested Cristiano Ronaldo, Gareth Bale and Marcelo, with Karim Benzema also missing because of a hamstring injury.
Asensio scored with a volley inside the penalty area after Theo Hernandez’s cross from the left wing.
Real host Leganes in the second leg at the Bernabeu on Wednesday, 24 January.
Zinedine Zidane’s side, who won the Champions League and La Liga in 2016-17, are fourth in La Liga, 19 points behind leaders Barcelona, and this was their first win in four matches in all competitions.
Real had the better chances in the first half as Raphael Varane headed an opportunity over the bar and Mateo Kovacic fired wide with only goalkeeper Nereo Champagne to beat.
However, Leganes, 13th in La Liga, nearly took the lead when Real defender Marcos Llorente headed on to his own crossbar.
The hosts had a further opportunity as Nordin Amrabat, on loan from Watford, crossed for Claudio Beauvue and his volley was well saved by Real goalkeeper Kiko Casilla.
However, it was Asensio’s first goal in 11 matches which gave Madrid the advantage going into next week’s second leg.
The other three first-leg quarter-final ties took place on Wednesday, with Barcelona falling to a surprise 1-0 loss at Espanyol.
Second-placed Atletico Madrid lost 2-1 at home to Sevilla, while Valencia, third in La Liga, hold a 2-1 advantage over Alaves.