Cristiano Ronaldo scored a stoppage-time penalty as Real Madrid survived a major scare to win 2-1 against struggling Elche on Wednesday night.
The Alicante side had the better of the first half but could not make the breakthrough and a Ronaldo free-kick just after half-time saw them trail.
But Richmond Boakye appeared to have salvaged a draw for the hosts when he headed them level in stoppage-time at the end of the game.
However, Carlos Sanchez's foul on Pepe handed Real a chance to win the game from the spot and Ronaldo, who now has nine goals in his past five games, did the rest to secure a 2-1 victory.
The victory sees Los Blancos move just two points behind Primera Division leaders Barcelona while Elche are still waiting for their first win of the season.
Ronaldo began in his usual barnstorming fashion and earned Real a corner after just a minute but it came to nothing.
You could have been forgiven for thinking that that early action would set the tone for the evening but Elche were determined to give as good as they got.
Diego Lopez was forced into a double save in the ninth minute as Sergio Ramos went in the book for a foul on Ruben Perez.
Damian Suarez whipped in the resulting free-kick with David Lomban's header bringing a diving save from the goalkeeper.
And from the following corner, Lopez was forced into another save from Sanchez.
Ronaldo took a long-range shot moments later which failed to trouble Manu Herrera and it was the home side who came close to breaking the deadlock as Javi Marquez brought another save from Lopez.
Marquez then dragged a shot wide before Manu was forced into his first save of the night in the 23rd minute but he easily gathered Angel Di Maria's shot.
Ronaldo, as usual, was providing Real's greatest threat and he saw two shots blocked away either side of Marquez clearing the bar when he should have done better.
Di Maria saw another shot saved by Manu as half-time approached but neither side could find a breakthrough before the interval.
Sami Khedira fired a shot over the bar just after the restart but it was not long before Ronaldo had the visitors ahead.
Six minutes into the second half, Perez fouled the Portuguese 25 yards out and the former Manchester United man fired through the wall to beat Manu who perhaps should have got more than a fingertip to it.
Karim Benzema had had a quiet evening up to then but he was alert enough to make a mess of a volley in the 65th minute.
Sanchez and Boakye both fired shots wide in the closing stages but the home side had to wait until the first minute of injury time for their equaliser.
Fidel Chaves gathered the ball from a throw-in and provided the cross which Boakye met with a near-post header which beat Lopez.
The drama did not end there though as Ronaldo scored his second from the penalty spot in the fourth minute of time added-on.
Sanchez and Pepe grappled in the area with referee Cesar Muniz Fernandez awarding the spot-kick and Ronaldo hammered home from 12 yards to spark wild celebrations with his team-mates.