Real Madrid warmed up for their Champions League game against Juventus with victory in La Liga when Cristiano Ronaldo's stoppage-time penalty sealed a 2-0 win at home to Malaga on Saturday.
It was far from the performance coach Carlo Ancelotti wanted to dispel doubts about Real's start to their domestic campaign a week away from the season's first Clasico against Barcelona, but it was enough to trim the gap with Barca and Atletico Madrid to two points before the Catalans regained a point in their late match.
Cristiano Ronaldo was comfortably Real's most dangerous player at the Bernabeu and the Portuguese forward curled a shot against the crossbar in the eighth minute.
The visitors did well to keep Real at bay until half time but fell behind in the first minute of the second half, when Angel Di Maria whipped the ball over from the right and it evaded Malaga goalkeeper Willy Caballero's despairing dive before nestling in the back of the net.
Caballero was in inspired form and pulled off a brilliant stop to deny Ronaldo eight minutes from time, and made another stunning save to palm away a low shot from substitute Jese two minutes later.
Real's record $137million signing Gareth Bale, who has been out for several weeks with a thigh strain, came on for Alvaro Morata with some 15 minutes left, suggesting he could play a part against the Italian champions on Wednesday.
Bale won a late penalty when the referee ruled he was fouled by Weligton in the area, and Ronaldo dispatched the spot kick low to Caballero's right for his eighth La Liga goal of the season.
Real have 22 points from nine matches, while Atletico and Barca missed the chance to equal the best start in La Liga history.
Barca's streak over
Barcelona were held to 0-0 at Osasuna, and fell one win short of matching best Spanish league start.
Barcelona's coach Gerardo Martino left Lionel Messi on the bench after he was also deemed fit to play after recovering from a muscle injury in his right leg.
Defender Carles Puyol played for the first time in seven months after recovering from knee surgery. The 35-year-old Spanish international was included in Barcelona's starting lineup after being cleared by team doctors earlier in the week. Puyol's last appearance came on March 12 of last season.
Atletico fell behind the leaders with a 1-0 loss at Espanyol.