Spanish police have arrested 50 people following a second night of clashes over the jailing of a 32-year-old rapper for a series of tweets insulting police and the monarchy.

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

Hundreds of protesters gathered under a heavy police presence in Madrid's Puerta del Sol square, calling for his release, later throwing bottles at police, who charged at them in clashes lasting several hours.

Police said that at least 15 people were arrested, while the city's emergency services said that 55 people were injured, including 35 officers.

The city's conservative mayor Jose Luis Martinez-Almeida condemned the incidents, tweeting: "The violent and those who do not accept the rules have no place in our society."

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

Demonstrators making their anger known in Madrid

Across Catalonia, regional police said that 31 people were arrested, including 10 in Barcelona, 14 in Lerida - where Pablo Hasel was arrested - five in Gerona and two in Tarragona.

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.

The rapper 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.

Last night's protest turned violent in Barcelona

Pablo 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 film-maker Pedro Almodovar and 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".