Karim Benzema scored two late goals to help Real Madrid come from a goal down to win 2-1 against Elche on Saturday.
Daniel Calvo had put Elche ahead just after the hour mark before the Frenchman scored twice in the last 20 minutes to give Madrid the win.
Elche came close to scoring several times with Thibaut Courtois forced into several fine saves.
Guido Carrillo nearly opened the scoring for Elche five minutes from half-time after Tete Morente dropped a ball into the box which he headed towards goal.
Sergio Ramos securing his first start in 10 games, had a penalty appeal waved away on 55 minutes after VAR found that Ivan Marcone had been fouled and not Ramos.
Madrid were made to pay for their missed chances when Calvo put Elche ahead with a header from a corner after 61 minutes.
However, their lead didn't last long as Benzema pulled one back for Zinedine Zidane's side just over 10 minutes later.
Substitute Luka Modric delivered a ball into the box and Benzema headed it in.
Madrid's winner came in the 91st minute after Benzema received the ball through a one-two with Casemiro before hitting a shot past Edgar Badia.
Real Madrid move into second - a point above Barcelona.
Meanwhile Atletico Madrid missed the chance to open up an eight-point gap at the top of La Liga after being held by Getafe.
Joao Felix thought he had broken the deadlock but Marcos Llorente was adjudged to have carried the ball out of play in the build-up.
Getafe's Allan Nyom was shown a straight red card for his challenge on Renan Lodi, before Luis Suarez struck the post in the closing stages.
Barcelona can cut the gap to four points if they beat Huesca on Monday.