A SCOT locked up in a Barcelona prison for more than a month because Brexit saw him labelled a “flight risk” has been celebrating after his lawyer managed to secure his release.

William Aitken was arrested on February 17 during demonstrations supporting Catalan rapper Pablo Hassel, who was sent to jail after being convicted over his lyrics criticising the monarchy.

Six other protesters were also detained but they were released, leaving the Scot as the only one to remain in detention.

The judge said that as a UK passport holder in a post-Brexit Europe, he was a “flight risk” as there were no reciprocal means of ensuring he would return to the court should he be allowed temporary freedom.

He sent Aitken into pre-trial detention because he did not appear to have “any work or family roots in our country” – although he has lived in the Catalan capital for more than four years with his partner Fernanda Soler, who had lodged his residency and banking documentation with the court.

However, David Aranda, a lawyer acting for pressure group Solidarity Alert, who represented him, took the case to an appeal at Barcelona’s Provincial Court, where, a judge decided to allow his freedom, overturning the prosecutor’s arguments, and ruling there was insufficient evidence to justify keeping him behind bars before his trial.

There are preconditions – Aitken will have to check in with the court every 15 days until his trial on public order offences and has had his passport confiscated until the case is resolved.

Aranda told The National late on Friday: “The court has resolved our appeal. They give us the reason and William will be released today,” although he added that the release could take some days to process.

In the event, Aiken was out of prison in time to mark his 31st birthday over the weekend. His partner said: “Yes, we are both home, finally.

“We had a great weekend with friends celebrating his freedom and his birthday.”

Solidarity Alert said the flight risk claimed made by the prosecutor to keep Aitken in jail was baseless.

“This is false because the agreement regulating the terms of the UK’s withdrawal from Europe establishes a similar system to that of European arrest warrants,” said the group. The Scot allegedly threw stones at police vans on the night of the protests and built barricades in the street from dumpsters.

His case was first publicised by The National before being reported by several Catalan publications.

Angela Crawley, the SNP’s shadow attorney general, also raised it with Foreign Secretary Dominic Raab.

She told The National: “I welcome the court’s decision to release William and I know his family will be relieved to have him home.

“This case raises concerns around the extradition powers negotiated with the EU which clearly fall short and risk others being held in foreign prisons without trial.

“I will be raising William’s treatment with the Foreign Secretary again, asking the Government to ensure that more is done to protect UK citizens living or travelling through EU countries.”