Lionel Messi scored his 500th Barcelona goal in second-half stoppage time as his side beat 10-man Real Madrid 3-2 in an unbelievable Clasico at Santiago Bernabeu, a victory that puts them top of LaLiga.
Substitute James Rodriguez had scored a dramatic late equaliser that looked like it would give Madrid a draw to put them on the brink of a first league crown since 2012, only for Messi to bring up his milestone with the last kick of the game.
Prior to those late goals, a breathless and controversial contest looked like it would be settled by Ivan Rakitic's excellent strike, especially when Sergio Ramos was sent off for a lunge on Messi.
But James then scored within four minutes of coming off the bench to send the home fans wild, only for Messi to steal the show with his second of the match.
The contest was typically controversial, Cristiano Ronaldo having a strong early penalty claim turned down, while Barca wanted Casemiro's opener chalked off as they claimed for offside against Ramos in the build-up, a goal that was promptly cancelled out by Messi before half-time.
Barca then called for Casemiro to be sent off as he got away with two first-half fouls after being booked, but it was Madrid's turn to be angry with the officials when Ramos was dismissed.
The story was still to be told, though, with James' strike followed by Messi's astounding 92nd-minute winner to ensure Spain's top-flight is in for a thrilling conclusion over the final weeks of the season.
Both sides are now level on points with Barca ahead by virtue of their head-to-head record, although Madrid still hold a crucial game in hand.
There was controversy inside two minutes when Ronaldo latched on to Dani Carvajal's cutback in the box and went down under Samuel Umtiti's challenge, but referee Alejandro Jose Hernandez Hernandez was unmoved.
Ronaldo then tested Marc-Andre ter stegen with two efforts, the second - after he had cut inside Gerard Pique - forcing the goalkeeper into a magnificent one-handed save.
Karim Benzema, meanwhile, produced a poor strike straight at Ter Stegen when presented with a decent shooting opportunity.
Luis Suarez fired wide with two attempts for Barca at the other end, his second chance set up by Paco Alcacer, who was starting in attack with Neymar out through suspension.
Messi was left bloodied after being caught by Marcelo's arm and had to play on with cotton wool in his mouth, before Gareth Bale – a surprise starter who was forced off before half-time with what appeared to be a recurrence of his calf injury – volleyed straight at Ter Stegen.
Madrid opened the scoring after 28 minutes through an unlikely source. Marcelo's cross found Ramos, who was not flagged for offside in a marginal call despite huge Barca claims, and he hooked an effort against the post, with Casemiro sliding in to finish the rebound left-footed.
But, against the run of play, Barca drew level within five minutes when Messi collected Rakitic's pass and glided past the challenges of Luka Modric and Carvajal before beating Keylor Navas down low from 12 yards.
Modric had a fierce long-range drive kept out by Ter Stegen as Madrid looked to respond, but the first half ended level after Barca protests for Casemiro to be given a second yellow card for his third foul of the match were ignored.
Madrid continued to dominate after the break, with Ter Stegen saving from Toni Kroos before he impressively managed to keep out a close-range Benzema header with his legs after great work from Marcelo down the left.
But Barca had a big chance of their own, Alcacer thwarted by Navas after a poor finish, having been found with space in the box by Rakitic.
And as Luis Enrique's side grew into the game, Navas got down sharply to keep out Pique's thumping header.
Ronaldo then wasted a glorious chance to get Madrid back in front, firing over the bar with only Ter Stegen to beat after Marco Asensio - Bale's replacement - had squared to him in the area after a breakaway from the hosts.
A thrilling game continued at the other end as Andres Iniesta found Suarez at the far post and the striker fired a shot that Navas superbly kept out from close range.
And Barca moved in front with 17 minutes remaining, Rakitic cutting inside Kroos and launching an unstoppable left-footed strike from 20 yards into the far corner.
Madrid's hopes of a comeback appeared to be over four minutes later, Ramos furious to be shown a straight red card for jumping in two-footed on Messi and sarcastically applauding the officials on his way off.
The impressive Navas somehow denied Pique from eight yards after substitute Andre Gomes had found him wide open and then also saved Messi's powerful drive.
And those stops became all the more crucial as James grabbed an equaliser with five minutes to play, converting Marcelo's cross with a high finish past Ter Stegen as the home support erupted.
But Messi had the last word, finishing off a slick move that had been started by Sergi Roberto, converting Jordi Alba's cutback with a trademark left-footed finish and celebrating by holding his shirt up to a dismayed Bernabeu.
Key Opta stats:
- Lionel Messi became the all-time highest scoring player in El Clasico in LaLiga (16), surpassing Alfredo Di Stefano (14).
- Casemiro is the first Brazilian player to score for Real Madrid in a league Clasico since Julio Baptista in 2007.
- Sergio Ramos has been sent off more times against Barcelona than against any other opponent in LaLiga (four).
- Cristiano Ronaldo has failed to score in his last four LaLiga games, equaling his longest drought in the competition (two times, October 2015 and September 2010).
- Marc-Andre ter Stegen made 12 saves against Real Madrid, his highest tally in a game for Barcelona (all competitions).