ATLANTA (AP) — An appeals court has ruled the federal government improperly ordered the deportation of a former Nicaraguan rebel fighter who had been in the U.S. for more than three decades.

Roger Ricardo Alfaro, a U.S.-trained Contra rebel who fought to overthrow the leftist Sandinista government in Nicaragua in the 1980s, fled to the U.S. and was admitted on a tourist visa in 1981. He successfully sought a year later to change his status to lawful permanent resident.

He was living in south Florida in December 2013 when he got a U.S. Immigration and Customs Enforcement notification that said he was subject to deportation because he had committed two or more crimes involving moral turpitude. When he challenged that, ICE added another charge, saying he had willfully lied on his 1982 application to adjust his immigration status, according to a July 13 opinion from the 11th U.S. Circuit Court of Appeals.

The government said Alfaro had lied when he answered "no" to a question on the application that asked whether he'd ever been arrested, convicted, or "confined to prison," the opinion says.

At some point in 1980, he and some other Contras were moving five Sandinista prisoners of war who were handcuffed and chained together when one of the other Contras killed one of the prisoners who tried to escape. Alfaro then cut the dead prisoner's hand off so he wouldn't weigh down the other prisoners as they all tried to reach shelter from enemy fire, the opinion says.

As a result, Alfaro was temporarily held in a trailer in the Nicaraguan jungle by his fellow rebels, the opinion says.

An immigration judge found that that confinement in a trailer meant that Alfaro had lied by answering "no" when asked if he'd ever been confined in a prison. Alfaro appealed to the Board of Immigration Appeals, which is part of the U.S. Department of Justice, and the board also found that he had been confined in a prison and ordered him deported.

Alfaro was deported to Nicaragua in January 2015. He appealed the Board of Immigration Appeals decision to the 11th Circuit.

The appeals court found that the board was wrong, saying, "we hold that as a matter of law, a rebel-controlled trailer in a jungle is not a 'prison.'"

Kathryn Mattingly, a spokeswoman for the Executive Office for Immigration Review, which includes the Board of Immigration Appeals, said the agency does not comment on circuit court decisions.

University of Miami School of Law professor Rebecca Sharpless, who was appointed by the 11th Circuit to represent Alfaro, said she couldn't believe the mistake that had been made.

"It's truly remarkable that it took this long for our justice system to wake up and realize the error in this case," she said in phone interview Tuesday.

The government has already conceded that at least one of the crimes of moral turpitude it had alleged in its initial effort to deport him — a Florida theft charge — does not constitute a crime of moral turpitude, so that rationale for deportation no longer exists, Sharpless said.

Alfaro is not in the U.S., but Sharpless declined to say where he is now. Alfaro was thrilled at the 11th Circuit decision and hopes to return soon to his family in Florida, she said.

"I am hopeful that the government will do the right thing in this case and bring him back," Sharpless said.