Italian authorities have granted refugee status to an Eritrean man who was the victim of one of the country’s most embarrassing cases of mistaken identity.

Last month a judge in Palermo acquitted Medhanie Tesfamariam Berhe of being a human trafficking kingpin, confirming he was the victim of mistaken identity when he was arrested more than three years ago in a joint operation by Italian and British authorities.

After the verdict he was moved to a deportation centre in Caltanissetta, Sicily, awaiting removal from the country. But on Friday a panel of judges from the refugee commission in Syracuse accepted Berhe’s request for asylum, meaning he is free to remain in Italy.

“I can’t describe how happy I am,” Berhe, 32, told the Guardian outside the expulsion centre. “It was a nightmare. A nightmare which lasted too long.”

Berhe was arrested in Karthoum, Sudan, on 24 May 2016. Italian and British authorities presented it to the press as a coup, mistaking him for one of the world’s most wanted human traffickers, Medhanie Yehdego Mered, AKA the General.

Within a few hours of Berhe’s arrest, hundreds of Mered’s victims claimed the wrong man had been detained. According to the suspect’s family, far from being a notorious trafficker he was an Eritrean refugee who earned his living on a dairy farm and working occasionally as a carpenter.

A three-year investigation by the Guardian uncovered witnesses and documents that the defence later produced in court to help prove his innocence.

A documentary made by the Swedish broadcaster SVT in collaboration with the Guardian revealed that the real Mered was living in Uganda’s capital, Kampala, spending his substantial earnings in nightclubs while Berhe faced up to 15 years in jail.

In addition to two DNA tests and an array of witnesses, perhaps the most crucial proof of Berhe’s innocence was a voice analysis of him and Mered, who had been caught on a wiretap in 2014. The result unequivocally concluded that the man in prison was not the trafficker.

But prosecutors continued to insist the man captured in Khartoum was the real smuggler and began waging an offensive against activists and journalists, tapping phone conversations among reporters, exposing sources.

The prosecutor in the trial, Calogero Ferrara, did not call a single witness to testify against Berhe, but at the end of his five hours of closing remarks on 17 June he dismissed suggestions they had the wrong man and demanded a 14-year prison term.

The judge, Alfredo Montalto, of the criminal court of Palermo, rejected the prosecutor’s claims. “It was a case of mistaken identity,” Montalto said on 12 July. “The man in prison was wrongly arrested.”

Berhe was found guilty instead of a much lesser charge of aiding illegal immigration for having helped his cousin to reach Libya. Because he had already served three years in prison, the judge ordered his immediate release.

Berhe’s laywer, Michele Calantropo, told the Guardian: “After the verdict I rushed to the prison alongside Berhe’s sister only to find out that they moved him to an expulsions centre for migrants. We had filed an official request for asylum. It wasn’t fair to move him there.”

“Medhanie’s judicial persecution has finally ended in the best way possible: with a refugee status to which he is fully entitled,” said Riccardo Noury, Amnesty International’s Italy spokesman. “I shudder to think where he would be now if the judicial error against him had not been exposed.”

Relatives have asked that Berhe be awarded damages for his wrongful detention and called for an investigation to be opened into why Sicily’s top prosecutors pursued the case.

“Berhe is free but this story won’t be over until they clear his name,” said Calantropo.