Pablo Hasel was meant to start jail time for a controversial conviction but the rapper and some supporters locked themselves in a university instead. Prosecutors took offense to the content of his tweets and song lyrics.
Dozens of Spanish police stormed a university in the northeastern town of Lleida and detained rapper Pablo Hasel on Tuesday.
Hasel had barricaded himself inside the university with around 50 supporters the day before in a bid to avoid jail.
Hasel had been given until Friday night to turn himself in to begin serving his sentence.
What happened at the University of Lleida?
Hasel, whose real name is Pablo Rivadulla, announced on Monday on Twitter: "I'm locked inside the University of Lleida with quite a few supporters so they'll have to break in if they want to arrest me and put me in prison."
He also published several tweets condemning his conviction, adding on Tuesday morning: "Tweets for which I'm going to be jailed in a few minutes or hours. Literally for explaining reality. Tomorrow it could be you."
A Catalan police spokesman told news agency AFP that officers entered then university early Tuesday "to enforce the judicial ruling" on his arrest.
Police in protective gear removed chairs, garbage bins and other objects to reach the spot where the singer was.
Spanish television showed images of police escorting him out of the university on Tuesday.
"They will never make us give in, despite the repression," Hasel said, his fist raised as he descended a staircase.
The case against Pablo Hasel
At issue was Hasel calling former King Juan Carlos I, who left Spain for Abu Dhabi after corruption allegations, a "thief" in his lyrics. His work also featured violent fantasies about conservative politicians.
Via Twitter, he accused police of torturing and killing demonstrators and migrants.
The reaction to Pablo Hasel's sentence
His sentencing was controversial and sparked protests in Madrid and Barcelona.
Hundreds of artists have signed a petition demanding Hasel's release, including film director Pedro Almodovar, Hollywood actor Javier Bardem and folk singer Joan Manuel Serrat.
Last week, Spain's left-wing coalition government unexpectedly pledged to reduce the penalty for "crimes of expression" such as those Hasel was convicted for.
The change would apply to comments made in the context of artistic, cultural or intellectual activities.
The government did not specifically mention Hasel or provide a timetable for the changes.