Lionel Messi scored the winner, and his 500th Barcelona goal sending the Catalans to the top of the La Liga Table
Casemiro started the scoreline before Messi and Ivan Rakitic responded with goals of their own, which gave Barcelona the lead.
Sergio Ramos was shown a red card for a wild lunge.
Substitute James Rodriguez earns the equalizer for Madrid late on.
But Messi, blazed through and fired from the edge of the area to give Barcelona the win.
This puts Barcelona level on points with Real Madrid, but has a better head-to-head record.
Barcelona have redeemed themselves with this match, having lost their Champions League quarter-finals against Juventus and their abysmal performance against Malaga recently.
What the Managers said:
Barcelona boss Luis Enrique: “We are first now but Madrid have an extra game. It will be tight until the end. We got the result we came here for.
“This is a season that weighs on us like five. So many things have happened, good things, not so good things, things I’ve already forgotten.
“The 2-2 goal was a terrible blow but players were able to come back in the last breath – the happy ending that we all wanted at Barcelona.”
Real Madrid coach Zinedine Zidane: “Nothing changes now. Maybe after today the league will be more open. But we still depend on ourselves.”
Casemiro (28′ minutes)
Ramos (Dismissed at 77′ minutes)
Rodríguez (85′ minutes)
Messi (33′ minutes, 90’+2 minutes)
Rakitic (73′ minutes)