Federico Valverde has scored three goals in Clasicos - one at Madrid, one at Barca and one in Saudi Arabia
Karim Benzema scored Real's opener after Vinicius Jr's shot had been saved into his path by Marc-Andre ter Stegen.
Federico Valverde doubled the champions' lead before half-time with a lovely 20-yard drive.
Ferran Torres pulled one back from Robert Lewandowski's flick-on but Rodrygo settled it with a penalty.
The rivals started the day with seven wins and a draw from their opening eight games - but Real go three points clear now as they remain unbeaten.
This was a first away La Liga defeat in almost a year in charge of Barcelona for Xavi.
Barcelona looked as if they were on their way back to the top of Spanish football towards the end of last season when they beat Real 4-0 at the Bernabeu.
They gambled in the summer by spending a lot of their future earnings on signings. The club hoped it would lead to instant success, which would in turn lead to more earnings.
But they face early elimination from the Champions League - and showed again how they are still behind their old rivals.
This is only their first defeat of the season - and they are still within three points of top spot in La Liga. But this is El Clasico - a game managers dare not lose.
Something for Xavi to think about is how they looked better after bringing on youngsters in Ferran Torres, Gavi and Ansu Fati.
Barca appeared down and out at 2-0 before those introductions. Fati's cross was flicked into the path of Torres, who scored his second Clasico goal at the Bernabeu of the year.
Fati then hit an acrobatic volley which went just wide during their brief hope of grabbing a point - before Rodrygo settled the game.
Benzema led Real Madrid to the Champions League and La Liga titles last season in a campaign which is likely to win him the Ballon d'Or.
He has had a slow scoring start to this season though. His opener, to cap off a swift counter-attack, was only his fourth La Liga goal of the season.
The France international thought he had a fifth in the second half with a fine finish from outside the box - but he had not heard the whistle going for an offside as he celebrated with the home fans.
One man in flying form before Sunday's game was Barcelona's Robert Lewandowski, who like Benzema is 34.
The two-time Best Fifa Men's Player netted nine goals in his first eight games in La Liga following a summer move from Bayern Munich.
But he lacked the clinical finishing of Benzema this time out. Most notably he slid a cross over an empty net from close range and drilled a free-kick straight into the wall.
The Pole will score plenty more goals this season but for now Benzema showed he is still the top striker in El Clasico.
-- Courtesy of BBC Sport