Real Madrid needed to make up ground and showed their intent from the start. They got a penalty when Kylian Mbappe pounced on Pau Cubarsi's mistake and was taken out by Wojciech Szczesny. Mbappe then beat Barca's goalkeeper from the spot, putting Real Madrid ahead just five minutes into the game.
Mbappe added another goal before the quarter-hour mark, staying onside and latching onto Vinicius Junior's through-ball before coolly slotting his shot past Szczesny. Thibaut Courtois denied Lamine Yamal and Gerard Martin, but Eric Garcia headed home after Ferran Torres flicked on Dani Olmo's corner.
Barca remained on the front foot, but Ferran couldn't convert Martin's low cross and Yamal's latest shot was saved. The 17-year-old met Ferran's lay-off with a superb first-time shot that curled into the bottom corner, equalizing the score.
The chances kept coming, and a mix-up between Mbappe and Dani Ceballos was punished by Raphinha racing onto Pedri's through ball and beating Courtois to complete a 15-minute turnaround. Moments after Raphinha headed over, Real Madrid thought they had another penalty but saw it ruled out, and instead had another mistake punished by Raphinha after he had pickpocketed Lucas Vazquez and fired home at close range.
The action was relentless, and Mbappe had a goal ruled out for offside moments prior to the break. Carlo Ancelotti made a double change ahead of the restart, but it did little to affect the overall flow.
Mbappe then came close to picking out the bottom corner, but eventually got his hat-trick when Vinicius raced onto Luka Modric's pass and laid the ball across for Mbappe to convert. Raphinha missed a big opportunity before Yamal and Ferran were both denied, but debutant Victor Munoz couldn't provide a late equaliser.
So, despite Fermin Lopez's late goal being ruled out for handball, Barcelona won to extend their lead atop LaLiga to seven points. They need just one win from their last three matches to win the title and complete their treble.
Barcelona also ended Real Madrid's four-game winning run in the league. Lamine Yamal was named Flashscore Man of the Match.
See all the match stats with Flashscore.