Pep Guardiola's men showed excellent resilience to bounce back from going a goal down after 22 seconds to defeat their bitter rivals at the Santiago Bernabeu
Jose Mourinho's men took the lead after only 22 seconds when Karim Benzema grabbed the quickest goal in Clasico history. The home side were pegged back on the half hour mark when Alexis Sanchez grabbed an equaliser in his first league appearance against Madrid.
A Xavi volley took a fortuitous deflection off Marcelo to give the visitors the lead, before Cesc Fabregas' header finished off a wonderful team move in the 66th minute in what proved to be the fixture's final strike.
The victory sends Barcelona level on points with Jose Mourinho's men and to the top of the Liga table due to their superior head-to-head record against Madrid, who have a game in hand.
In one of the most astonishing starts in the history of the Clasico, Real Madrid were a goal to the good within 22 seconds. Victor Valdes' poor clearance fell to the feet of Angel Di Maria who drilled the ball into the penalty area only for Sergio Busquets to block its progress. Mesut Ozil's attempted volley deflected off Busquets into the path of Benzema to fire home six yards from goal.
Madrid were left to rue opportunities to double their lead when Barcelona drew level on the half hour mark with Messi on hand to turn provider. The 24-year-old bypassed several challenges before sliding a weighted through ball to Alexis Sanchez, who calmly slotted past Casillas from the edge of the area to bring his side back into the game and all square at the break.
After a edgy opening to the second period, Barcelona were handed the lead thanks to a large slice of fortune on 53 minutes. Xavi's speculative volley 25 yards from goal took a massive deflection off Marcelo, fooling a wrong-footed Casillas with the ball spinning off the post and into the back of the net.
Cristiano Ronaldo, who had in the first half skewed a shot wide of the target when Di Maria was perhaps better placed to his right, then squandered a golden opportunity to level the contest. Xabi Alonso's cross found the Portuguese completely unmarked inside the area, but his header drifted wide of the post.
Madrid were made to pay, as Barca extended their lead in the 66th minute after a breathtaking counterattacking move. Messi slid the ball out to the right for Dani Alves to whip a beautiful cross towards the back post where an unmarked Cesc Fabregas was on cue to coolly head the ball into the far corner in what was to be the final goal of a pulsating encounter.
Next up for Real Madrid is a trip to Ponferradina on Tuesday as they look to defend their Copa del Rey title. Barcelona now head to Japan where they will feature in the Club World Cup. Their first task will be a semi-final meeting against either Esperance or Al Sadd on Thursday.