Zinedine Zidane masterminded an unlikely win in his first El Clasico in charge as Real Madrid head coach.
Gerard Pique gave Barcelona the lead early in the second half, but goals from Karim Benzema and Cristiano Ronaldo sealed the three points for Real.
Los Blancos went into the match 10 points behind its Catalan rival at the top of La Liga and while victory by no means puts it back in contention, the win has at least reignited faint hope that Barcelona can be caught.
The game started at a frenetic pace, as Real captain Sergio Ramos picked up his customary yellow card inside ten minutes.
Soon after, Neymar came away with the ball after a tussle with Sergio Ramos, raced into the Real penalty area and squared to ball to Luis Suarez.
With the goal gaping at his mercy, the Uruguayan somehow contrived to mis-kick his effort and the ball rolled harmlessly between his legs and out for a goal kick.
After 14 minutes, all corners of the ground — Barcelona and Real Madrid fans alike — stood up in unison for a minute’s applause in memory of Johan Cruyff.
Barcelona soon carved Real’s defense open yet again. The ball found its way to Rakitic’s feet after Pepe deflected Suarez’s cross into the path of the Croatian.
Real’s Costa Rican keeper, Keylor Navas, got down quickly to his right to push Rakitic’s curling shot away.
It took until two minutes before half time for Real to conjure up its first chance of the game.
Following a marauding run forward, full-back Dani Carvajal picked out Benzema who was afforded the freedom of Barcelona’s penalty box, but the Frenchman could only shin the ball high over the crossbar.
Barcelona continued to dominate possession at the start of the second half and it wasn’t long before they found an opening.
10 minutes after the restart, Suarez found an unusually subdued Lionel Messi on the edge of the box.
The Argentine hit an audacious chip which was headed for goal, only for Navas to claw the ball behind for a corner at full stretch.
However, they wouldn’t be denied for long. From the resulting corner, Gerard Pique lost his marker, Pepe, before climbing high to power a header into the bottom corner, this time giving Navas no chance.
Real drew level just seven minutes later. Marcelo embarked on a brilliant solo run onto the edge of the Barcelona area and found Toni Kroos out on the right.
The German’s shot deflected up into the air and Benzema acrobatically dispatched the ball past Claudio Bravo into the bottom corner.
After a hectic few minutes, the game eventually settled down and Barcelona began to dictate play, but the match again sparked to life with ten minutes to play.
First, Suarez latched onto Messi’s lofted through ball and hit a shot with the outside of his boot that whistled inches past the post.
A minute later, Real thought it had found the winner. Ronaldo’s perfectly lofted cross found Gareth Bale at the far post and the Welshman rose high above Jordi Alba to head the ball past Bravo.
As he raced away in jubilation, the linesman raised his flag for a foul on Alba and his celebrations were cut short.
Ronaldo then cut inside onto his right foot and fired a shot which clipped the top of the crossbar — and had Zidane doing cartwheels in his technical area.
Ramos finally received his long-awaited second yellow card for a rash challenge on Suarez and it appeared as though Real would be hanging on for a point for the final six minutes.
Real counter-attacked almost immediately, as Bale powered into the box and stood up a perfect cross to Ronaldo who was waiting at the far post, ready to pounce.
Dani Alves mis-judged the flight of the ball and Ronaldo calmly chested the ball down and slotted past Bravo.