Cristiano Ronaldo scored a crucial late winner as Real Madrid gave their LaLiga title defence a much-needed boost with a thrilling 3-2 victory over struggling Malaga at the Santiago Bernabeu.
With 14 minutes remaining, the Portugal international had a penalty saved by Roberto Jimenez but converted the rebound to settle an end-to-end encounter in which Madrid twice lost the lead.
It had looked like Ronaldo was about to suffer another frustrating match in front of goal after missing multiple chances, only for him to be handed a reprieve when substitute Luka Modric won the spot-kick and gave him the chance to score only his second league goal of the season.
Earlier, Karim Benzema headed in what was also his second top-flight goal of the campaign, ending a seven-game scoring drought - the longest of his LaLiga career - in the process.
Diego Rolan capitalised on a Toni Kroos mistake to stun the hosts with an equaliser that was Malaga's first away goal of the league season, but Casemiro quickly restored order with Madrid's second headed goal in a frantic start.
After the break, Kiko Casilla then failed to keep out Gonzalo Castro's 30-yard strike and it looked like Madrid would drop more points until the late drama saw Ronaldo settle the match.
The victory moves Madrid within seven points of leaders Barcelona and three behind second-placed Valencia ahead of their title rivals' crunch clash at Mestalla on Sunday evening (Monday morning AEDT).
Madrid only took nine minutes to breach Malaga's backline, as Benzema followed up his double against APOEL with the easiest of finishes.
The chance came after Marcelo's cross from the left found Ronaldo at the far post and the Portugal forward athletically headed against the crossbar, giving his strike partner a simple task to nod into an empty net on the rebound.
A sliding Dani Carvajal forced Roberto into a diving save and Isco also tested the away goalkeeper from 18 yards, but Malaga stunned the Bernabeu with an 18th-minute equaliser.
Kroos carelessly lost possession deep in his own half as he attempted to pass to Raphael Varane and that allowed Keko's right-wing cross to find Rolan completely unmarked, the Uruguay international chesting down and drilling in from 12 yards.
However, Madrid responded only three minutes after that strike, Casemiro latching on to Kroos's curling corner to power a header in from eight yards.
There was a moment of concern for Zinedine Zidane's men when a Keko delivery led to Castro's header being hacked away by Varane from close to the goal line.
Madrid should have extended their lead when Benzema dragged wide from an excellent shooting chance and two efforts from Ronaldo – a first-time curling effort and a thumping header - were impressively kept out by Roberto as Malaga, who lost Juankar to injury, remained in the game.
There was still time for a controversial end to the first half when substitute Paul Baysse sent a magnificent header past Casilla, only for the referee to rule he had fouled Carvajal, leaving Michel demanding answers on the touchline.
Kroos's powerful strike was pushed away by a busy Roberto early in the second half but a back-and-forth contest took another twist after 58 minutes when Castro collected Keko's pass and somehow beat Casilla, who should have done better, with a 30-yard strike.
Another Madrid chance passed when Ronaldo failed to turn in Varane's header from inside the six-yard box after Lucas Vazquez's threatening delivery had created the opportunity.
Zidane brought on Modric for a quiet Isco and the Croatia midfielder made a vital contribution, being felled by Luis Hernandez in the box after taking a clever touch in latching onto Vazquez's cross.
Ronaldo, who was short on confidence, went for power from the spot but saw Roberto make an excellent save, only for the rebound to fall kindly for the forward to convert with a left-footed strike, the relief on his face clear to see.
And this time Madrid did not lose their lead, Ronaldo having a second goal ruled out by an offside flag against creator Vazquez in the final minutes as the champions secured a vital victory.