An immigration judge approved the release of Abdulkadir Sharif Abdi on Tuesday in a courtroom full of cheering friends and relatives, the latest twist in his long fight to avoid deportation to Somalia.

The government has increased deportations to Somalia in recent years, but the Twin Cities immigration court agreed to take another look at Abdi’s case last year after his attorney, John Bruning, said that his client’s criticism of extremist group al-Shabab and its efforts to recruit local men could endanger him if he returned to his homeland.

After moving to the U.S. as a refugee in the 1990s, Abdi joined a gang and was convicted of car theft, receiving stolen property and three drunken-driving charges. He received a deportation order in 2002 and checked in with immigration officials for years — in the meantime leaving the gang life, sobering up and becoming a leader in the Somali addiction recovery community. He became a housing manager at the Park Avenue Center, a Minneapolis alcohol and drug treatment facility.

But in January 2018, Abdi was detained at a routine check-in. He was scheduled last March to be a passenger on a deportation flight of 69 Somalis, two-thirds of whom had criminal convictions, according to Immigration and Customs Enforcement. Abdi’s attorney sought a so-called withholding of removal, a sort of legal limbo that prevents him from being deported while not guaranteeing him asylum or citizenship.

Judge Sarah B. Mazzie granted that request in November, but Abdi remained in detention at the Freeborn County jail pending a final custody review. On Tuesday, Mazzie ordered him to be released on his own recognizance.

“I know we have a bright future,” said Rhoda Christenson, Abdi’s wife. “He’s going to be OK … and for that I’m grateful.”

Abdi will still have periodic check-ins with immigration authorities, but Christenson said she was working with attorneys to try to prevent him from having to do so indefinitely.

Anab Ali, his sister, also cheered the decision outside the courtroom.

“Every mistake he made when he was so young,” she said. “He changed a lot a long time ago.”