Real Madrid moved up to third in La Liga after coming from behind to beat Leganes 3-1 on Wednesday.
Unai Bustinza put the hosts ahead in the sixth minute when he dived at the feet of Theo Hernandez and managed to divert his clearance into the net with his head.
But Real, who started with Gareth Bale on the bench, hit back before half-time with goals from Lucas Vazquez and Casemiro.
Sergio Ramos wrapped up the win with a 90th-minute penalty as Zinedine Zidane’s side closed the gap on leaders Barcelona to 14 points, while they are now seven points behind second-placed Atletico Madrid.
Having stunned Real Madrid in the quarter-finals of the Copa del Rey last month, Leganes made the perfect start in their bid for a repeat result as they scored the opening goal in the sixth minute.
Bustinza’s initial effort from a corner was blocked on the line but he dived at the feet of Theo Hernandez to score.
However, Real responded quickly and led at half-time thanks to two well-worked goals.
Casemiro was involved in both, flicking through for Vazquez to level in the 11th minute and then combining neatly with Karim Benzema and Vazquez before sweeping home just before the half-hour mark.
It remained 2-1 until the 90th minute as both sides struggled to fashion any clear chances in the second half.
Claudio Beauvue forced a sharp save from Kiko Casilla in the 64th minute but otherwise there was little in the way of goalmouth action until Mateo Kovacic was fouled in the box and Ramos dispatched the penalty in the absence of Cristiano Ronaldo.