It took Real until the 90th minute to make sure of the victory, though, with Ramos scoring from the penalty spot after Mateo Kovacic had been fouled. (Photo: AFP)

Madrid: Cristiano Ronaldo was rested as Real Madrid came from behind to win 3-1 at Leganes on Wednesday and move back up to third place in La Liga.

Unai Bustinza had put Leganes in front at Butarque, raising hopes that the home side could record another famous victory just weeks after they ousted Real from the Copa del Rey.

However, the reigning European champions turned this Madrid derby around before half-time with Lucas Vazquez and Casemiro both on target. Sergio Ramos sealed the win with a late penalty, and Real have now taken 16 points from the last 18 available in La Liga.

They are still a massive 14 points adrift of unbeaten league leaders Barcelona, but they are up to third above Valencia and within seven points of city rivals Atletico, who are second.

With the games piling up for his team, coach Zinedine Zidane rested Ronaldo for this rescheduled fixture, initially postponed in December due to Real's involvement in the Club World Cup.

With Toni Kroos, Luka Modric and Marcelo all injured and in a race against time to be fit for the Champions League last 16, second leg against Paris Saint-Germain in a fortnight, this was another chance for some of Real's fringe players to shine.

Theo Hernandez and Isco were among the starters, but Gareth Bale was back on the bench as he struggles to rediscover his best form.

Kiko Casilla was handed a start in goal in place of regular number one Keylor Navas, and Casilla was picking the ball out of his net inside six minutes, with Bustinza bravely stooping to score from almost on the line after his initial effort had been blocked.

However, it took Real just five minutes to draw level, Casemiro helping the ball into the path of Vazquez, who slotted home low. Casemiro is a defensive midfielder by trade but he put Madrid in front just before the half-hour mark, scoring at the end of a lovely one-touch move also involving Karim Benzema and Vazquez.

It took Real until the 90th minute to make sure of the victory, though, with Ramos scoring from the penalty spot after Mateo Kovacic had been fouled. Zidane's side will bid to continue their improved form when they host Alaves at the weekend.