Barca were the better side and earned a well deserved win against a Real Madrid side that at times seemed resigned to their fate.
The defeat was another blow to Barca and manager Xavi Hernandez after they were left on the brink of Champions League elimination following a draw with Inter Milan last week.
A sensational strike from defender David Alaba and a late goal from Lucas Vazquez gave Carlo Ancelotti's side three points.
Zinedine Zidane's side joined Atletico Madrid on 66 points and moved top of the table, although Atletico can reclaim first place when they visit Real Betis on Sunday.
Real Madrid captain Sergio Ramos once again proved to be the man for the big occasion as he converted a fiercely debated penalty to help his side to a 3-1 win.
Violent protests have been taking place in the region following the imprisonment of nine Catalan political and social leaders for their role in organising an independence referendum in 2017.
First El Clasico of the season to be played on the weekend of October 27-28.