Authorities sought to keep Catalonia’s separatist movement from disrupting the game viewed by 650 million people worldwide.
The match in Barcelona’s Camp Nou stadium began without incident and was halted only briefly when some fans threw balls onto the field bearing a message for the Spanish government to open a dialogue with the separatists.
The game, which drew nearly 100,000 spectators, ended in a scoreless draw.
Thousands of police and private security guards were deployed in and around the stadium.
In the street clashes, riot police used batons to force the crowd back, some threw objects at officers lined up behind shields and other protesters fought among themselves.
Authorities said at least 12 people were injured and two were arrested, Spain’s national news agency Efe reported.
At least four plastic bins were set on fire, and the smell of smoke wafted into the Camp Nou.
When the game ended, fans were directed to leave on the stadium’s south side to avoid the clashes outside.
The separatists sought to promote their independence bid by using the media coverage of the game between Barcelona, the Spanish league leaders, and its fierce rival Real Madrid.
Known as El Clasico, the game was postponed from October 26 amid violent protests by the separatists.
As crowds entered Europe’s largest football stadium, security guards confiscated masks of Barcelona’s Argentine star Lionel Messi from supporters, apparently to ensure they could be identified on closed-circuit cameras if they broke the law.
As the game began, some fans held up blue signs saying “Spain, Sit and Talk” and “Freedom”. Others chanted, in Catalan, “Freedom for the Political Prisoners”.
Those messages referred to the Spanish government’s refusal to discuss the wealthy north-eastern region’s independence, as well as the recent imprisonment of nine of the movement’s leaders convicted for their roles in a failed 2017 secession bid.
A shadowy online group called Tsunami Democratic, which was behind the protest, had posted a message on social media saying: “Hello, world! Tonight Tsunami has a message for you.”
Protest organisers said over 25,000 people signed up to demonstrate near the stadium in Barcelona, Catalonia’s capital, although it was hard to distinguish between protesters and fans.
There was a festive atmosphere before the game, though some protesters briefly blocked main roads to the stadium.
The Barcelona team asked its fans to behave with civility and not to affect the match.