Franck Kessié’s stoppage time goal secured a 2-1 win for the Catalan club which now moves 12 points clear of Madrid atop the La Liga table, with 12 games remaining.
Barça was the better side throughout the game but initially went behind after defender Ronald Araújo turned a cross into his own net.
Supported by a capacity crowd inside the Camp Nou, the 26-time league champion rallied and equalized through Sergi Roberto just before halftime.
Real Madrid’s Marco Asensio then saw his late effort ruled out by the video assistant referee (VAR) for offside before Kessié wrapped up the tie in the 92nd minute.
“We never gave up, but we are already four games behind them. Nothing is impossible, but the truth is that it’s very difficult,” Real goalkeeper Thibaut Courtois told Movistar Plus, speaking about his side’s league title hopes.
Real Madrid has suffered with inconsistency this season but came into Sunday’s game off the back of a 6-2 aggregate win over Liverpool in the Champions League.
But while Los Blancos did show glimpses of quality, the team relied too many times on Courtois who kept his side in the match with some impressive saves.
‘Painful’ defeat for Madrid
Despite the hosts being largely the better side, Madrid manager Carlo Ancelotti said he was proud of his team.
“We’ll fight to the end in every competition, we’re full of confidence. We’ll fight for La Liga until the end,” he said.
The Italian, though, was left angry by the offside decision that ruled out Asensio’s 81st minute goal, which could have been the winner for Madrid.
VAR judged that the forward was ahead of Barcelona’s defenders, albeit by the narrowest of margins.
Less than 10 minutes after the decision, Kessié scored the eventual winner after smashing home Alejandro Balde’s cross which gave Barcelona its 100th El Clásico victory.
“We’re sad, it’s painful, but we’re proud of the performance we put in,” Ancelotti added.
“It was a complete display from the first minute until the last. We haven’t won it due to an offside which was extremely doubtful and we’re heading back to Madrid with those doubts still in our minds.”
Barça, which remains embroiled in an alleged referee payment scandal, faces Elche in its next league match after the international break while Real Madrid takes on Real Valladolid.