Gareth Bale scored on his return from injury as Real Madrid beat Espanyol to move up to third in La Liga.
The Welshman scored three minutes after coming on as a second-half substitute to put Real Madrid 4-1 ahead.
Two goals from Karim Benzema and Sergio Ramos' header had given Real a 3-1 half-time lead, with Leo Baptistao replying for Espanyol.
Raphael Varane was sent off before Roberto Rosales pulled another goal back, but Real held on for a 4-2 win.
The win sees Santiago Solari's side move back above Sevilla and narrow the gap on city rivals Atletico Madrid to five points.
They may have ultimately secured their third win in a week, but this topsy-turvy match sums up Real Madrid's inconsistent season.
The European champions look as fearsome as ever going forward, but their vulnerability at the back perhaps explains why they are 10 points behind leaders Barcelona.
They made the perfect start, taking the lead after just four minutes. Luka Modric's curling shot was only parried by Diego Lopez and Benzema was alert to score the rebound from close range.
Modric had a role in Real Madrid's second 11 minutes later, the Croat collecting Tony Kroos' short corner and putting in a cross that was converted by Ramos.
But with Real looking in control, Espanyol got back into the game out of nothing. Baptistao pounced on a loose ball in the box before powering a shot into the roof of the net.
Real Madrid looked to have struck the decisive blow when Benzema scored his second just before half-time, the Frenchman playing a neat one-two with Vinicius Junior before stroking the ball into the corner.
With Real Madrid looking in control, Solari was able to bring on Bale, who has been sidelined for three weeks with a calf injury, midway through the second half.
Three minutes later, with virtually his first touch, Bale showed great skill to backheel the ball away from two defenders before powering a shot past Lopez for his 11th goal of the season in all competitions.
But with the game seemingly won, Real allowed Espanyol back into the game.
First Varane was deservedly shown a straight red card for tripping up Pablo Piatti when he was clean through on goal before Rosales pulled one back with a thumping volley.