Match ends, Real Madrid 3, Barcelona 4.
Barcelona breathed new life into their La Liga title hopes as a Lionel Messi hat-trick helped fire them to victory in a thrilling match at 10-man Real Madrid.
Andres Iniesta shot into the top corner before Karim Benzema's brace put Real ahead.
Messi restored parity soon after but Cristiano Ronaldo restored Real's lead from the penalty spot.
After Sergio Ramos was sent off, Messi won the game with two penalties.
It was Messi's second hat-trick in a row as he became the second highest scorer in La Liga history, moving ahead of former Real striker Hugo Sanchez onto 236 goals.
The Argentine also became the all-time top scorer in Clasicos with 21 goals, surpassing Real legend Alfredo Di Stefano, as Barcelona moved to within one point of Sunday's opponents.
Messi has produced some indifferent performances this year but he has been back to his best lately with an inspirational performance in Barca's Champions League passage past Manchester City followed by successive league trebles.
Atletico Madrid's 2-0 win at Real Betis earlier on Sunday means they top La Liga, level on points with city rivals Real but ahead on their head-to-head record this season, but Barca are now within a point of both.
The defending champions travelled to the Bernabeu having lost two of their last four league matches, while Real had not been defeated in their last 31 matches in all competitions.
But Barcelona signalled their early intent through a brilliant early strike into the top corner by Iniesta, after Messi's precise through ball.
Real, who had won their last 17 matches in a row at the Bernabeu, were soon ahead as Benzema made up for an early miss with a quick-fire double.
First he headed home Angel Di Maria's cross and then, four minutes later, the pair combined again as the Frenchman controlled on his thigh before slotting the ball into the net.
For a match that meant so much to both sides, it was surprisingly open and Barca had Gerard Pique to thank for not going further behind as he cleared Benzema's effort off the line.
Neither side looked sure defensively and, just before the break, Messi cut inside the area to fire the visitors level to cap a thrilling half of football.
Real were ahead again in controversial circumstances soon after the restart, as Ronaldo scored from the penalty spot despite being tripped by Dani Alves just outside the penalty area.
The match swung again though when Ramos was shown a straight red card for fouling Neymar, allowing Messi to equalise from the penalty spot.
Alves then hit the post as Real looked content to hold out for the draw before Messi won the game, again from the spot, after Iniesta was sandwiched by Xabi Alonso and Dani Carvajal.
Barcelona have won six of their last 11 league fixtures at the Bernabeu and, also through to the quarter-finals of the Champions League, they will believe they can go on to defend their La Liga title.
- 14AlonsoBooked at 85mins
- 3PepeBooked at 43mins
- 4RamosBooked at 63mins
- 19ModricBooked at 88minsSubstituted forMorataat 90'minutes
- 22Di MaríaBooked at 35minsSubstituted forIscoat 85'minutes
- 9BenzemaSubstituted forVaraneat 66'minutes
- 7Cristiano RonaldoBooked at 85mins
- 5da Silva Coentrão
- 22Alves da Silva
- 16BusquetsBooked at 66mins
- 4FábregasBooked at 43minsSubstituted forSánchezat 78'minutes
- 11NeymarSubstituted forPedroat 69'minutes
- 13Pinto Colorado
- 24Roberto Carnicer
- Alberto Undiano Mallenco
- Shots on Target
Second Half ends, Real Madrid 3, Barcelona 4.
Lionel Messi (Barcelona) wins a free kick in the defensive half.
Foul by Álvaro Morata (Real Madrid).
Offside, Barcelona. Alexis Sánchez tries a through ball, but Dani Alves is caught offside.
Attempt missed. Alexis Sánchez (Barcelona) right footed shot from the centre of the box misses to the left. Assisted by Lionel Messi.
Sergio Busquets (Barcelona) wins a free kick in the defensive half.
Foul by Gareth Bale (Real Madrid).
Xavi (Barcelona) wins a free kick on the left wing.
Foul by Xabi Alonso (Real Madrid).
Substitution, Real Madrid. Álvaro Morata replaces Luka Modric.
Foul by Pedro (Barcelona).
Daniel Carvajal (Real Madrid) wins a free kick on the right wing.
Luka Modric (Real Madrid) is shown the yellow card for a bad foul.
Lionel Messi (Barcelona) wins a free kick in the attacking half.
Foul by Luka Modric (Real Madrid).
Andrés Iniesta (Barcelona) wins a free kick in the defensive half.
Foul by Isco (Real Madrid).
Offside, Barcelona. Dani Alves tries a through ball, but Alexis Sánchez is caught offside.
Cristiano Ronaldo (Real Madrid) is shown the yellow card for a bad foul.