Italian investigators who pursued a case against an Eritrean man accused of being one of the world’s most-wanted human traffickers in a case of mistaken identity were guilty of “serious neglect”, judges in Sicily have said.

In a 400-page judicial report, the court of assizes traced the three-year ordeal of Medhanie Tesfamariam Berhe, a 30-year-old refugee released from an Italian jail in July.

According to the judges, the prosecutors’ accusations “appeared patently inconsistent and inadequate’’, adding that, in some instances, the accusations against Berhe were “dubious on a logical and conceptual level”.

The arrest of Berhe in 2016 was presented to the press as a brilliant coup by Italian and British authorities, who mistook him for Medhanie Yehdego Mered, AKA “the General”, a smuggling kingpin. The Eritrean was supposed to be the first human trafficker to be extradited from Africa and was regarded as an “Al Capone of the desert” by the authorities.

But within a few hours of the arrest being announced, hundreds of Mered’s victims were claiming the wrong man had been detained. Far from being a notorious people smuggler, Berhe earned his living working on a dairy farm and occasionally as a carpenter. What’s more, Berhe did not even resemble the trafficker Mered, whose picture the prosecutors had released to the press.

The judges at the court of assizes highlighted “serious neglect” on the part of investigators, with reference in particular to a Facebook chat between Mered’s wife, Lidya Tesfu, and Berhe.

Although the two never met, Berhe once flirted with her via Facebook. Tesfu told him she was married, but when Berhe continued to contact her she said: “I don’t need anyone but my husband”.

However, when the prosecutors filed the chat into evidence, they neglected everything except Tesfu’s final message, which created the impression she was married to Berhe and was missing him.

In their judicial report, the judges stressed that the chat “emphasised by the prosecutors since the beginning of this trial, represents, on the contrary, a clear sign on the part of the woman to decline the man’s attempts to flirt with her”.

“Failing to produce the rest of the chat except the line ‘I don’t need anyone but my husband’ was, according to the judges, a serious neglect,” the report said.

The Guardian investigated the case, uncovering new witnesses and documents which were partially produced on Wednesday by the judges. They included private messages sent from the real trafficker’s Facebook account, in which Mered, still at large, said another Eritrean man – Berhe – had been arrested in his place.

Berhe spent more than three years in jail and was granted refugee status one month after his release in July.

Michele Calantropo, Berhe’s lawyer, told the Guardian: “Finally, after three years, the court has undeniably recognised the case of mistaken identity, but this story won’t be over until they clear Berhe’s name.”

Berhe was cleared of trafficking but found guilty of the lesser charge of aiding illegal immigration, for having helped his cousins reach Libya. Because he had already spent three years in jail, the judge ordered his immediate release. Berhe’s defence lawyer has said he will appeal against the conviction.

“Helping family members during the desert trip is perfectly normal in Africa,” said Calantropo. “Plus, my client did not receive a penny for this help offered to his cousins.”

To date, the prosecutors and the British National Crime Agency have never admitted their responsibilities in the mistaken identity case.