The imam accused of masterminding the Barcelona terrorist attacks should have been deported at the end of his prison sentence for drug smuggling, but overturned the ruling by arguing it would breach his human rights, it has emerged.

Islamic preacher Abdelbaki Es Satty was told he must comply with an expulsion order when he left jail in April 2014, according to the Spanish daily, El Mundo.

But the 42-year-old Moroccan won an appeal against the decision after arguing his case in front of a judge.

The judge who made the decision is said to have accepted Es Satty's claims his forced removal would be a breach of his international rights.