They had been trailing 2-0 at Villarreal
Real Madrid rescued all three points from their clash at Villarreal to return to the top of the La Liga table.
But the capital club had to work hard for the result after finding themselves 2-0 down at the Yellow Submarines.
Second half goals from Manu Trigueros and Cédric Bakambu left Zinedine Zidane's side with a sinking feeling.
But Real roused themselves to produce a stirring comeback.
First Gareth Bale scored his second La Liga goal since his return from injury by heading in.
Then Cristiano Ronaldo powered in a penalty that was furiously debated by Villarreal and their staff.
And the winner for Real duly came with seven minutes to go through Alvaro Morata to dispel any sense of crisis after a midweek loss to Valencia.
Earlier, Barcelona had gone top (Real Madrid still have a game in hand on the teams behind them) after defeating fourth placed Atletico Madrid 2-1 at the Vicente Calderon.
Lionel Messi's winner four minutes from time decided the game in Barca's favour. Rafinha had given the Catalans a lead before Atletico defender Diego Godin equalised with 20 minutes to go.
Sevilla also remain in the hunt for a first La Liga title since the 1945-46 season. Saturday's 2-1 win at Real Betis in the Seville derby keeps them three points behind Real.