Real, who had won the previous five Clasicos, are nine points clear of Sevilla with nine matches to go, with third-placed Barcelona a further three behind with a game in hand.
Pierre-Emerick Aubameyang scored twice on his Clasico debut and set up Ferran Torres.
Aubameyang and Ronald Araujo headed in crosses from Ousmane Dembele before the break and Aubayemang then flicked the ball into the path of Torres for their third.
Ex-Arsenal striker Aubayemang chipped in a fourth from a Torres pass.
Barca are now unbeaten in 12 games and Xavi said: “I don’t know if we can win the title, we can’t rule out anything. Maybe we’re a bit late, but this is a very big win for us.
“We were much better than Real Madrid. We played almost as a home team in the the ground. It’s a day to enjoy, not only as a Barca manager but also a fan.
“We could easily have scored five or six. We changed our negative dynamic of losing the last few Clasicos.”
Barca midfielder Sergio Busquets added: “If we still have a small chance to make a run for the title, we will fight until the end. It’s very difficult but in football anything can happen. We are Barca.”
Real boss Carlo Ancelotti took responsibility for the heavy loss, saying “it’s my fault” – but urging his team to “forget it and move on”.