Spanish police arrested some 50 people overnight following a second night of clashes over the jailing of a rapper for a string of tweets insulting police and the monarchy.

Angry demonstrations first erupted on Tuesday night in Catalonia after police detained Pablo Hasel, 32, who was holed up in a university in that region to avoid going to jail in a controversial free speech case.

And the protests swelled on Wednesday with hundreds gathering under a heavy police presence in Madrid's Puerta del Sol square and calling for his release, later hurling bottles at police, who charged at them in clashes lasting several hours, AFP journalists said.

Police said at least 15 people were arrested, but were due to issue an update on Thursday morning, while the city's emergency services said 55 people were injured, among them 35 police officers.

In Barcelona, demonstrators lobbed objects at police and set barricades ablaze, with police firing foam rounds and charging at the protesters.

Across Catalonia, the Mossos d'Esquadra regional police said 31 people were arrested, including 10 in Barcelona, 14 in Lerida, where Hasel was arrested, five in the northern city of Girona and 2 in Tarragona.

Violent protests have broken out over Pablo Hasel's arrest for the second night running in Barcelona
Violent protests have broken out over Pablo Hasel's arrest for the second night running in Barcelona AFP / Josep LAGO

Medics said eight people were slightly injured.

At least 15 people had been arrested on Tuesday night in protests in several Catalan cities in which more than 30 people were injured, among them 19 police officers, officials said.

Hasel missed a Friday deadline to turn himself in and begin serving a nine-month jail term handed down in 2018.

At issue is a series of tweets calling former king Juan Carlos I a mafia boss and accusing police of torturing and killing demonstrators and migrants.

Hasel is known for his hard-left views, but his case has become a cause celebre among campaigners, who say that prosecuting him is a dangerous assault on free speech.

His sentence caused outrage in Spain, with stars, including the film-maker Pedro Almodovar and the Hollywood actor Javier Bardem, expressing support for his cause.

Amnesty International denounced the move saying jailing the rapper for song lyrics and tweets was "unjust and disproportionate".