The European champions fell 2-1 behind the visitors but late goals from Mariano and Sergio Ramos ensured they kept their six point lead over Barcelona.
Another Sergio Ramos late show secured an unconvincing 3-2 win over Deportivo La Coruna as Real Madrid struggled in the absence of Cristiano Ronaldo, Karim Benzema and Gareth Bale.
It was the first time since May 2014 that Madrid had started a La Liga game with neither Bale or the rested Ronaldo and Benzema in their line-up, and they were indebted to late goals from Mariano Diaz and Sergio Ramos to secure a new club record of 35 matches unbeaten.
Madrid unsurprisingly enjoyed the greater share of possession, but Deportivo – sensing they will not have many better opportunities to get a result at the Bernabeu with the hosts’ star trio absent – gave a good account of themselves.
Deportivo thought they had been made to rue missed opportunities just after the break, as Alvaro Morata put an anonymous first half behind him with a stunning long-range strike.
But two goals from former Madrid prospect Joselu with just over an hour played turned the match on its head and left the hosts rattled.
However, Zinedine Zidane’s bold attacking tactics towards the end paid off, as Mariano levelled and then Ramos – also Madrid’s last-gasp saviour in El Clasico last week – secured the win, ensuring the club’s unbeaten record remains intact ahead of Thursday’s Club World Cup semi-final.
Although Madrid’s start was bright, they needed a helping hand from some calamitous defending to craft their first chance.
Juanfran hesitated in the Deportivo area and his attempted clearance was charged down by Nacho Fernandez, but the Spain international delayed his shot and Raul Albentosa made a vital block.
Deportivo posed a threat on the break despite Madrid’s control and went close to finding the breakthrough just before the half-hour mark, as Celso Borges directed Albentosa’s low cross towards the bottom-left corner, only for his Costa Rica team-mate Keylor Navas to palm it around the post.
The hosts should have capitalised on that let-off shortly after, but James Rodriguez shot straight at Przemyslaw Tyton when played through on goal by Isco.
Deportivo continued to look unperturbed by Madrid’s superiority, though, and struck the post 10 minutes before the break – Borges again the central figure, as his header came back off the upright and looped agonisingly over the head of the lurking Guilherme.
Morata endured an ineffective first half in which he touched the ball just 12 times, but he made a decisive impact just after the break, slamming a brilliant effort into the bottom-right corner from 30 yards.
That should have sent the hosts on their way to a routine win, but Deportivo had different ideas and stunned Madrid with a quick-fire double just after the hour mark.
Casemiro played himself into trouble on the edge of his own area for Deportivo’s first, as Florin Andone robbed the Brazilian and Joselu hammered into the top-left corner from 20 yards.
Andone was crucial for the former Castilla striker’s second as well, the Stoke City loanee latching onto a ball from the right and finding the net, despite Navas partially blocking his shot.
But, as so often under Zidane, Madrid rallied.
Mariano drew them level with six minutes to go, meeting Lucas Vazquez’s cross and beating Tyton with an unconventional finish off the top of his back.
And Ramos crushed Deportivo’s spirit in the second minute of stoppage time, heading in Toni Kroos’ corner to keep Madrid six points ahead of Barcelona at the top.