BARCELONA, Spain -- Cristiano Ronaldo scored late for 10-man Real Madrid to snatch a 2-1 comeback win at Barcelona and revive its slim hopes of challenging for the Spanish league title on Saturday.

Madrid ended Barcelona's Spanish record unbeaten streak at 39 games across all competitions with its first come-from-behind win at Camp Nou since 1965, according to STATS.

In Zinedine Zidane's first clasico as a manager, Madrid avenged a 4-0 home loss to Barcelona it endured under Rafa Benitez in November by dealing the Catalan club its first defeat since Oct. 3.

More from FoxSports

On a night that Barcelona honored Johan Cruyff with a moving tribute, it was Ronaldo and Madrid's star forwards that outperformed Lionel Messi, Neymar, and Luis Suarez.

After a lackluster first half, Barcelona's Gerard Pique opened the scoring with a header in the 56th.

But Karim Benzema equalized six minutes later, and Ronaldo slotted in the winner in the 85th, moments after Madrid's Sergio Ramos received a second booking.

"Madrid is the deserved winner," Pique said. "Even before Ramos' sending off, there were five minutes when we didn't have control of the match. I don't know if we got tired, but we couldn't find a way to attack."

The big win kept Madrid in third place, one point behind Atletico Madrid after its 5-1 win over Real Betis, reducing the deficit with Barcelona to seven points with seven rounds left.

Given the considerable gap and dwindling chances to overtake both frontrunners, Madrid's best shot at silverware still rests in the Champions League, where it will play German side Wolfsburg on Wednesday.

"Step by step, first we have to overtake Atletico Madrid because we are still third, and then we will see what happens," Zidane said. "What I can say is that winning here is a huge reward for our players because the truth is that they played an enormous match.

"It's very important for our morale to win here, and just before we play a game in the Champions League in Germany."

Despite the loss, Barcelona's quest to repeat its rare treble of Liga, Copa del Rey, and European Cup from last season remains intact. Barcelona hosts Atletico in the Champions League on Tuesday.

"Their first goal unnerved us and unfortunately we lost our first game at home" this season, Barcelona coach Luis Enrique said. "We have to shake it off and recover for the Champions League, which will be a demanding match. We have to think that we are still the leaders with seven rounds left."

Before kickoff, Barcelona played a video of many former players giving thanks to former player and manager Cruyff, who died of lung cancer last week. The 90,000-plus crowd responded with a long ovation, and formed a huge mosaic with the message "Thanks Johan" in Catalan while they sang the club anthem before a minute of silence. The same message was also painted on the side of the pitch and worn on the players' shirts.

Another round of applause came at the 14-minute mark, in honor of his number as a player.

After halftime, the intensity revved up, and Keylor Navas had to dive and stretch his fingertips to turn Messi's crafty lobbed shot past his post. From the resulting corner, there was nothing Navas could do to keep out Pique's pointblank header, when Pique ran around Neymar and Suarez toward the near post to free himself from Pepe.

Madrid quickly leveled against the flow of the match when Marcelo led a disorganized attack that undid Barcelona when Toni Kroos' deflected pass fell to Benzema to sweep in.

While Barcelona battled to regain control, Madrid mounted a wave of counterattacks that eventually paid off. Gareth Bale appeared to have scored but his goal was waived off for a foul on Jordi Alba. Moments later, Ronaldo galloped down and sent a ball off the top of the bar.

Ramos' second yellow card for a clumsy foul on Suarez didn't swing the flow back Barcelona's way, and Madrid got the decisive goal when Bale crossed the ball to Ronaldo at the far post. He chested the ball down after Dani Alves mistimed his challenge and drilled it under Claudio Bravo for his league-leading 29th goal of the season.

Elsewhere, Valencia lost at Las Palmas 2-1 in the debut of coach Pako Ayestaran.