Real Sociedad did enough to frustrate the visitors for 80 minutes, but Gareth Bale’s superb header sealed three points for Los Blancos, who notched up their 10th straight league win and kept their title hopes alive.
After a goal-less first half, the home side looked in control in the second half and created some good goal scoring opportunities. In absence of Ronaldo and Benzema, Madrid struggled to create clear cut openings and were in search of an inspiration from somewhere to break Sociedad’s resilience.
Zinedine Zidane's side went into the match just a point behind leaders Barcelona and second-placed Atletico Madrid and knowing that victory would take them top of the table for at least a few hours, with both their rivals playing later in the day.
With Cristiano Ronaldo and Karim Benzema injured and one eye perhaps on the visit of Manchester City in wednesday's UEFA Champions League semi-final second leg, Madrid struggled to break down a resilient Sociedad side who beat Barca at Anoeta just three weeks ago.
Bale missed three clear-cut chances, while Jese Rodriguez was also thwarted by goalkeeper Geronimo Rulli and a stubborn home defence.
But the Welshman, whose late goal secured the 3-2 comeback with over Rayo Vallecano last week, steered in a powerful header in the 80th minute to salvage a win which piles pressure back on Atletico and Barca. It was 19th goal of the season,
Nacho almost found a breakthrough as he burst into the area following Bale's flick-on, but Rulli did enough to block his effort before Aritz Elustondo cleared the danger.
Sociedad continued to frustrate the visitors after the break, but Bale spurned a glorious opportunity to break the deadlock when he shot straight at Rulli from just eight yards out after Yuri Berchiche made a mess of clearing a James cross.
Modric's excellent run and pass sent Jese through to the right of the area, but his cross-cum-shot was parried by Rulli and eventually cleared, as Zidane brought on Isco in a bid to find a crucial breakthrough.
But it was Bale who made amends for his earlier misses to find a way through. Isco found Lucas Vazquez wide on the right, and Bale converted his cross high past Rulli at the near post with an emphatic header.
Of his 19 goals, nine of them are headers, which is more than any other player in Europe’s top five leagues. Also, he was involved in 30 goals this season for Madrid in just 28 games.
Sociedad pushed for an equaliser and Keylor Navas, largely a spectator throughout, made a fine low stop to hold on to Mikel Oyarzabal's header from Asier Illarramendi's cross.
But Madrid held on to keep the pressure on Barca and Atleti, and can now turn their focus on their crucial midweek meeting with City.
Watch Bale's goal below
Watch Bale's goal below