Federico Valverde smashed Real, who had lost their previous two games, into the lead from Karim Benzema’s pass.
Barcelona’s Ansu Fati, 17, levelled from Jordi Alba’s cross, becoming the youngest goalscorer in El Clasico history.
Sergio Ramos scored from the spot after he was fouled by Clement Lenglet and Luka Modric smashed in a late third.
The result takes Real top of the fledgling La Liga table with 13 points from six games, six points above Barcelona.