A Palermo judge has acquitted an Eritrean man 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 between Italian and British authorities.

The arrest of Medhanie Tesfamariam Berhe in 2016 was presented to the press as a brilliant coup by Italian and British authorities, who mistook him for one of the world’s most-wanted human traffickers, Medhanie Yehdego Mered, aka the General.

But Judge Alfredo Montalto of the criminal court of Palermo on 12 July rejected prosecutors’ claims and ordered the immediate release of Berhe, who was arrested in Khartoum, Sudan, on 24 May 2016 with help of the British National Crime Agency and the Sudanese police.

“It was a case of mistaken identity,” the judge said. “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, but because he had already served three years in prison, the judge ordered his immediate release.

“I have no words to explain the way I feel,” said Hiwett Tesfamariam, Berhe’s sister, who had travelled from Norway for the verdict. “It was a nightmare. A real nightmare.”

Michele Calantropo, Berhe’s lawyer, said: “After three years, finally the judge confirmed what we have been saying: we had a farmer in jail and a smuggler at large.”

Despite the judge’s ruling, the NCA insisted it had got the right man.

The NCA said: “The NCA assisted Italian partners in locating a specific individual. That man has today been convicted of significant people smuggling offences. We remain confident in our intelligence gathering, and believe the support provided to Italian authorities in this case was consistent with good operational practice.”

Francesco Lo Voi, the Palermo chief prosecutor also refused to apologise for the mistake. “At least the judge charged him with aiding illegal immigration,” he said.

Led by Italian prosecutors, the hunt for Mered and his affiliates began after a shipwreck in October 2013, in which 368 people died a few miles off the Italian island of Lampedusa. The next day Italy and its allies in Europe declared war on human traffickers. The goal was to capture the smugglers who organised the crossings. Amid growing public disquiet about the arrival of thousands of migrants on boats each week, the idea gained immediate support.

The Eritrean was apparently the first human smuggler to be extradited from Africa and regarded as the “Al Capone of the desert” by the authorities.

The analogy with the American mobster is not coincidental. In order to capture the Eritrean, authorities in Palermo convinced their EU counterparts to join the crusade on an alluring premise: that the same tactics used to combat the Sicilian mafia in the 1990s could ensnare modern human smugglers – wiretaps and the intuition that among smugglers lies a power structure regulated by a code of honour.

However, within a few hours of Berhe’s arrest, hundreds of Mered’s victims claimed the wrong man had been detained. According to Berhe’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.

Among many factors that pointed to his innocence, including two DNA tests and an array of witnesses, was a documentary by the Swedish broadcaster SVT, in collaboration with the Guardian, which revealed that the “real” Mered was living in the Ugandan capital, spending his substantial earnings in Kampala nightclubs while Berhe faced up to 15 years in jail.

The most recent, and perhaps 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, wiretapping the phone conversations among reporters that exposed their alleged error and the journalists’ sources.

In the last few months, as more than 44,000 signatures have been gathered in favour of Berhe’s release, hundreds of people have been protesting in Oslo, Stockholm, London and Frankfurt, calling for Italian authorities to release the arrested man. They are all Eritreans and many of them were trafficked to Europe by Mered, who appears to be still on the run.

Despite the fact he had not been able to provide a single witness to testify against Berhe, at the end of his five-hour closing remarks on 17 June the prosecutor Calogero Ferrara dismissed suggestions they had apprehended the wrong man and demanded a 14-year prison term.

But Berhe’s saga, a case that has become one of the most spectacular examples of mistaken identity in the last 30 years, may not be over. Relatives have asked that Berhe be awarded damages for his wrongful detention and that an investigation be opened into Sicily’s top prosecutors who, they argue, are guilty of having bungled a high-profile arrest, covered it up and framed an innocent man for the ruthless and lucrative crimes of another.