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.
Efficient Real brush off recent defeats
Real Madrid boss Zinedine Zidane has not lost any of his six matches as a manager at the Nou Camp, with three wins and three draws.
Morale may have been low after defeats in their previous two games by Cadiz, in La Liga, and Shakhtar Donetsk, in the Champions League.
But they started brightly when Benzema fed Valverde, who slammed the ball into the far corner, leaving Neto with no chance.
Fati’s almost immediate equaliser made it the first time both sides scored in the opening eight minutes of a Clasico in La Liga since 1940.
After that, Barca threatened to take control but Real did well to turn the tide.
The turning point was a lengthy video assistant referee decision. Referee Juan Martínez Munuera did not spot Lenglet’s pull on Ramos’ shirt but eventually gave a penalty after viewing it on the screen.
Ramos’ low penalty beat Neto and marks the first time he has scored 10 La Liga goals in a calendar year.
There was time for a late third as Luka Modric stepped past Neto before a classy finish.
Real are unbeaten in three Clasicos for the first time since 2012-13.
Questions for Koeman?
It is perhaps too early to talk about real pressure but Barcelona’s tally of seven points from five games is as bad a start as boss Ronald Koeman could have feared.
They were OK for large parts of El Clasico and dominated for a period but Real deserved their win in the end.
Scorer Fati was one of three teenagers in Barca’s team, alongside Pedri and right-back Sergino Dest, who was the first American to play in El Clasico.
Fati – who became the first player under the age of 18 to score in El Clasico – and Dest, who joined from Ajax at the start of this month, were two of Barca’s better performers.
Koeman will surely be quizzed on how Philippe Coutinho, who did not have a good game, played the full 90 minutes – or why he did not make any changes until the 81st minute.
Antoine Griezmann and Ousmane Dembele, two of the most expensive players of all time, came on too late for any real impact.
Lionel Messi was far from his best and has not scored in six Clasicos.