Karim Benzema saved Real Madrid's blushes by scoring a superb late goal to snatch a 3-2 win at home to La Liga basement side Huesca on Sunday and keep up coach Zinedine Zidane's perfect start since the Frenchman returned to the club.
The last-gasp win left Madrid third in the standings with 57 points after 29 games, while second-placed Atletico Madrid have 59 and runaway leaders Barcelona are on 69.
Huesca took a shock lead in the third minute of their first league visit to the Bernabeu when Cucho Hernandez smashed a cross from Ezequiel Avila past goalkeeper Luca Zidane, who was surprisingly brought into the team by his father.
Madrid drew level in the 25th when Isco knocked home a cross from full debutant Brahim Diaz to score for the second time in two games since being brought back into the team by Zidane, having been frozen out by former coach Santiago Solari.
Real went ahead after the hour mark with an acrobatic finish from close range by Dani Ceballos and Gareth Bale should have clinched victory when he slid in to meet a cross from a few metres out but somehow sent the ball over the bar.
Huesca were always threatening and seized their moment in the 74th with a short corner routine, Xabier Etxeita equalising with an unorthodox header.
But Madrid averted an embarrassing slip-up in Zidane's second game back at the Bernabeu thanks to his compatriot Benzema, who curled the ball into the top corner in the 89th.
The defeat left Huesca rooted to the bottom of the table on 22 points, seven away from escaping the relegation zone.
(For more sports news and updates, follow Ahram Online Sports on Twitter at @AO_Sports and on Facebook at AhramOnlineSports.)