Barcelona bounced back from conceding the fastest goal in El Clasico history to stun Real Madrid and replace their rivals at the top of La Liga.
Real were three points ahead of Barca with a game in hand and Karim Benzema gave them the lead inside 23 seconds.
Goalkeeper Victor Valdes was at fault but his blushes were spared by Alexis Sanchez's drilled equaliser.
Xavi's deflected strike put Barca ahead before Cesc Fabregas completed the triumph with a diving header.
Moments before that, Cristiano Ronaldo missed a glorious opportunity to level the match when he nodded wide from an unmarked position.
Ronaldo endured a miserable evening, wasting another fine chance to make it 2-0 and producing a poor free-kick from just outside the penalty area at 1-1.
The result sees Pep Guardiola's men go level on points with Jose Mourinho's Real, but the Catalans have a superior goal difference.
Real still have a game in hand but pre-match talk of the tide turning at the summit of Spanish football appears misguided.
Barca are now unbeaten in six visits to the Santiago Bernabeu in all competitions and seven matches against Real.
Given Barca's domination of all-comers in recent years - and with Real eyeing a first league title since 2008 - this was billed as the biggest Clasico in recent history.
It was a cold, wet night in the Spanish capital but more than 85,000 fans packed into the stadium and the players entered to a cauldron of noise.
Yet for all the pre-match hype and excitement, few could have predicted the start that was to follow.
With virtually the first touch of the match, Valdes accidentally played a pass straight to Angel di Maria and he looked to feed Benzema in the box.
The ball was cleared to the edge of the area where Mesut Ozil produced a volley that was deflected into the path of Benzema, and he poked home from close range.
Barca looked utterly shell-shocked and Valdes sat on the floor grinning in total disbelief.
Real had won the last 72 league games in which they had taken the lead and, despite Lionel Messi forcing a fine save from Iker Casillas, the hosts were in total control.
Benzema went close with a header before Ronaldo was denied by Valdes from distance and then skewed horribly wide from the 18 yards.
That miss would prove costly as, six minutes later, Messi fed Sanchez and he slotted a brilliant finish beyond Casillas.
By half-time, Barca had established an element of control and, after Ronaldo's free-kick was easily parried by Valdes, the visitors benefited from a huge slice of fortune.
A clearance fell to Xavi in a central position 20 yards out and his volley hit Marcelo, left Casillas wrong-footed and trickled in off the post.
Barca were now dominating the midfield battle and extended their advantage with an outstanding team goal.
Messi fed Dani Alves on the right and the Brazilian's teasing cross was headed in at the back post by an on-rushing Fabregas.
Benzema and substitute Kaka went close late on while Andres Iniesta almost made it 4-1, but there was no coming back for Real and the celebrations were all Barca's.