Every morning for three years, a prison guard would wake him by calling someone else’s name. At every court hearing, a judge would order him to stand and sit back down, using a name that was not his own.

Medhanie Tesfamariam Berhe was the victim of what has become one of Italy’s most notorious cases of mistaken identity. Detained in May 2016, he was accused by prosecutors in Palermo of being one of the world’s most sought-after human traffickers, Medhanie Yehdego Mered, aka the General. While the real smuggler lived it up in Africa, Berhe, who had earned his living milking cows and working occasionally as a carpenter, faced up to 14 years in jail.

His ordeal began when a Facebook friend request he had speculatively sent to Mered’s wife, finding her attractive, led investigators to conclude he was the smuggler operating under a new identity.

“More than once I contemplated taking my life,” Berhe, 32, told the Guardian. “When you live through such an injustice and discover you’re helpless to do anything about it, you lose the will to live. Try to see it my way: I wasn’t arrested, I was kidnapped and my three years in jail were like an endless nightmare which all started with a friendship on Facebook.”

The saga ended last month when a judge in Sicily acquitted Berhe of a charge of human trafficking, confirmed he was a victim of mistaken identity, and ordered his immediate release.

Today Berhe lives as a free man in a small apartment among the alleyways of Palermo’s historic centre, having been granted asylum by Italy. His years in jail have made him reticent and wary.

“Sometimes I’m terrified the police will arrest me and my nightmare will start all over again,” he said. “From that hellish day I was arrested, my life will never be the same.”

Berhe awaits the verdict in the courtroom in Ucciardone prison, built in the 1980s for mafia trials. Photograph: Alessio Mamo/The Guardian

On the afternoon of 24 May 2016, Berhe, a refugee from Eritrea, was drinking coffee in a bar on the outskirts of Khartoum, the Sudanese capital, when six police officers pulled a hood over his head, took him away and forced him on to a flight to Rome.

His arrest, after an investigation spanning two continents and five countries, was presented to the media as a triumph for a new anti-trafficking strategy. The suspect was touted as the “Al Capone of the desert” and the first human smuggler to be extradited from Africa. But on his arrival in Italy he had no idea what he was supposed to have done wrong.

“I thought they wanted to extradite me to Eritrea because I had deserted the military,” he said. “During my first interrogation in Rome they told me I was accused of being Mered, a human trafficker. I thought they were crazy.”

Berhe was eventually transferred to Palermo’s Pagliarelli prison to await what would become a long and controversial trial. Two DNA tests, an array of witnesses and reporting by the Guardian and New Yorker, who spoke to the real smuggler, all pointed to his innocence but the ordeal continued.

It transpired that the smuggler had been in jail in the Middle East – most likely the United Arab Emirates – for using a forged passport when Italian prosecutors travelled to Sudan and arrested Berhe in his place. Mered’s incarceration meant wiretaps Italian investigators had on his phone had gone quiet, as had his Facebook posts. The investigators assumed Mered had changed his number and social media accounts.

Berhe is temporarily living in a small apartment in Palermo Photograph: Alessio Mamo/The Guardian

A few months earlier, Sicilian prosecutors had learned that an Eritrean named Medhanie had become Facebook friends with the trafficker’s wife, Lidya Tesfu. They decided this account must be Mered’s, based on his and Berhe’s shared first name. Britain’s National Crime Agency provided the telephone number associated with the account to Sicilian prosecutors, who tracked it to Khartoum and issued an arrest warrant.

“If I could go back in time, I’d cut off the finger I used to send a friend request to that woman in the autumn of 2015,” Berhe said. “How could I have known she was Mered’s wife? She just looked nice. That Facebook contact landed me in this absurd situation.

“If Mered hadn’t been arrested in the UAE, the Italians would have likely arrested the real trafficker in Khartoum. And if I hadn’t friended Lidya, by this time I probably would have reached my family in Europe.”

Tesfu herself gave evidence that Berhe was not her husband, but the prosecutor Calogero Ferrara dismissed it along with all other suggestions that he had put the wrong man in the dock. At the close of the trial, he demanded a 14-year prison sentence.

Meanwhile Mered had been revealed by the Guardian and the Swedish broadcaster SVT to have been released from jail in the UAE and to be spending his substantial trafficking earnings in the Ugandan capital, Kampala, where he was a regular in nightclubs.

“I knew that while I was locked up, Mered was enjoying his freedom somewhere in Africa,” Berhe said. “But I don’t blame him. It’s not his fault I was arrested in Khartoum, and he didn’t keep me in jail for three years.”

Berhe was cleared of trafficking but found guilty of the lesser charge of aiding illegal immigration for having helped his cousin reach Libya. Because he had already spent three years in jail, the judge ordered his immediate release.

“I still don’t understand why I was found guilty of aiding illegal immigration,” he said. “Migrants don’t take cash during their desert journey because they risk getting robbed. That is why my cousin asked me to forward his money to a man who would help him on his way. This is perfectly normal in Africa, especially among Eritreans, because we have no passport. How else are we supposed to reach Europe?”

With asylum secured in Italy, Berhe has the rest of his life ahead of him. “People ask me what I’m going to do now that I’m free,” he said. “Well, first I need to realise that my nightmare is over and this freedom is not a dream. And if it is, I beg you: don’t wake me up.”