LLEIDA, Spain — Violent street protests erupted in some Spanish cities on Tuesday night following the arrest of a rap artist who barricaded himself at a university with dozens of supporters to avoid prison and has portrayed his case as a fight for free speech.

In Barcelona, several thousand protestors set trash cans on fire and threw rocks at the police. Several stores and a bank were damaged amid chaotic scenes on one of the city's main streets. Smaller demonstrations took place in Valencia and Palma de Mallorca, Spanish media reported.

A 24-hour standoff between police and Spanish rapper Pablo Hasél ended Tuesday when anti-riot officers arrested the artist shortly after dawn and escorted him out of Lleida University's rectorate building. He and more than 50 supporters locked themselves inside the university in Spain's northeastern Catalonia region at midday on Monday.

Hasél was sent to prison, where he's set to serve a 9-month sentence for insulting the monarchy and glorifying terrorism.

The university barricade was the rapper's latest effort to avoid serving his sentence and to draw attention to what he says is a campaign for freedom of expression. He has faced criticism and legal action over some of his statements, includes ones about the monarchy and the need for armed resistance.

"We will win! They will not bend us with all their repression, never!" the 32-year-old rapper said as he passed TV news cameras.

The case of Hasél, whose name at birth is Pablo Rivadulla Duró, has drawn increasing attention in Spain, with many members of the public, artists, celebrities and politicians showing their support and demanding a change in the country's so-called "Gag Law."

Spain's left-wing coalition government also unexpectedly announced last week that it would change the country's criminal code to eliminate prison terms for offenses involving freedom of expression. It did not specifically mention Hasél or set a timetable for the changes.

The rapper is no stranger to controversy. With an artistic opus that includes songs with strong anti-establishment criticism, he has seen his notoriety amplified among the wider Spanish public with every run-in with authorities.

Having faced charges on at least four occasions for assault, praising armed extremist groups, breaking into private premises or insulting the country's monarchy, in 2014 he was given a suspended 2-year prison term. But in a new case tried in 2018, judges handed him a reduced sentence of 9 months behind bars for a song about former King Juan Carlos I and 64 tweets he posted between 2014 and 2016.

The tweets straddled the line between opinion and calls to violent insurrection, with several mentions of ETA and Grapo, two now-defunct armed extremist groups in Spain. In the song, Hasél rapped about corruption tied to the former monarch but also talked about him as a wife-beater, a drunk, head of a mafia mob and a frequent user of prostitution.

Spain's National Court on Monday rejected his latest appeal to be kept out of prison. Judges said the sentencing came on the back of a suspended one and that offenders need to serve prison time if they relapse.

Sparing Hasél from imprisonment, the court said, would be "discriminatory" to other convicts, adding that the campaigning around his case could be used to change laws in parliament but that courts needed to apply the existing criminal code.

"I won't allow them to tell me what I have to think, feel or say," Hasél told The Associated Press late Monday. "This serves me as an extra stimulus to keep writing the same songs."

Jordi Dalmau, head of the Mossos d'Esquadara police for western Catalonia, said Hasél's arrest, which involved dismantling barricades of desks and benches blocking the building's entrance, had been carried out "with normality" and the activists did not resist. The rapper had refused last week to voluntarily respond to a summons to show up for prison.

Before being hurled into a police car, he shouted to supporters "Death to the fascist state!"

Over 200 artists, including film director Pedro Almodóvar and actor Javier Bardem, had signed a petition last week in support of the rapper. Amnesty International noted that Hasel's case was the latest in a string of trials of artists and social media personalities under the 2015 Public Security Law introduced by a conservative government.

Valtònyc, another rapper sentenced on similar grounds in 2018, fled to Belgium, where judicial authorities have rejected Spain's extradition request. Other recent cases have involved puppeteers purveying political satire and bloggers joking about assassinations of the 1939-1975 authoritarian regime of Gen. Francisco Franco.

The Spanish government's eleventh-hour proposal to change the criminal code under the law is being rejected by the conservative and far-right opposition.

But Tuesday's arrest also caused a new political storm in the ruling left-wing coalition led by Socialists from their smaller partner, the far-left United We Can (Unidas Podemos) party.

"All those who boast of this "full democratic normality" and consider themselves progressive should feel ashamed," the party tweeted Tuesday. "Will they cover their eyes? There is no progress if we refuse to acknowledge the current democratic deficits."

__

Parra reported from Madrid. AP journalists Renata Brito in Barcelona and Ciarán Giles and Aritz Parra in Madrid and contributed to this report.