Thibaut Courtois made two injury-time saves as Real Madrid earned a narrow home win over Rayo Vallecano to go third, at least for a day.
Karim Benzema got the winner with a confident 13th-minute finish for just his second goal in 13 La Liga games.
Lucas Vazquez had a shot cleared off the line before Toni Kroos hit the post, and Emiliano Velazquez went close for Rayo.
Sergio Ramos had a goal disallowed for offside, before Courtois’ late heroics.
Ex-Manchester United forward Bebe had already tested the Belgium keeper with a stinging drive from long range by the time Courtois blocked a 92nd-minute bicycle kick from Alex Alegria in the penalty area, also fencing away Velazquez’s follow-up.
Wales forward Gareth Bale was absent with an ankle problem as Real beat one of their city rivals to record a third consecutive clean sheet for the first time in the Spanish league since September 2015.
Frenchman Benzema, 30, hobbled off injured after a blow to his shin, with Brazilian 18-year-old Vinicius Junior replacing him for the final 12 minutes.
Santiago Solari’s side are now two points behind leaders Barcelona, who play at Levante on Sunday at 19:45 GMT. Sevilla can climb back above Madrid when they host Girona on Sunday.
Rayo remain second bottom in 19th, four points from safety.
Real Madrid next play in the Club World Cup semi-finals against Japanese side Kashima Antlers in the United Arab Emirates on Wednesday, a 16:30 GMT kick-off.
The other semi-final will be played between Copa Libertadores winners River Plate of Argentina and UAE champions Al Ain.
Earlier on Saturday, Atletico Madrid moved level on points with Barcelona in second as Antoine Griezmann scored the winner in a 3-2 victory at 12th-placed Real Valladolid.