A court in Sicily has ordered the immediate release of an Eritrean man accused more than three years ago of managing an extensive people-smuggling network for those trying to cross the Mediterranean Sea.

It was a case of mistaken identity, his lawyer said.

“It was a long battle to free a poor boy unjustly accused of being a human trafficking kingpin,” Michele Calantropo, the lawyer, said in a phone interview.

Medhanie Tesfamariam Behre, 32, was acquitted of human trafficking charges on Friday. But he was found guilty of a lesser charge, aiding illegal immigration, based on messages on his cellphone that mentioned migrants trying to escape to Europe.

“We will appeal the verdict because Mr. Behre never abetted illegal immigration,” Mr. Calantropo said. “But we are very happy that the judge said he is not the smuggling kingpin.”