In Judge Sarah Mazzie's courtroom this week, cheers and applause broke out. It was unusual for immigration court.

Hundreds of Somalis had been sent back over the past two years. But Abdulkadir Sharif Abdi wasn't. After a long legal battle, the civil war refugee, who is a former Minneapolis gang member, was now free.

Outside the courtroom, Rhoda Christenson was on the phone with Abdi, her husband, after his appearance. He was in a holding cell, still handcuffed and shackled.

Abdi came to Minnesota from Somalia as a refugee. He's now 40. But when he was younger, he was involved in gang activity that got him into trouble with law enforcement. Court documents say Abdi was stabbed in the neck by a rival gang member.

That history led to a deportation order against him. But it wasn't possible to take him back to Somalia, which had no functioning government. So Abdi was released from custody. He was required to check in regularly with Immigration and Customs Enforcement. It was routine — until he was arrested in January 2018.

"I was here when it happened," Christenson recalled. "I had been with Abdi for five years. I went to all his check-ins with him. Were we ever nervous? No. Were we ever worried about the outcome? Did I ever think that he would be arrested? No. We just did that normal thing."

Part of why Christenson was confident is that Abdi is a different person now. He left gang life and became a youth advocate. He's well known in the alcohol and drug recovery community. Abdi connected with other Somalis who struggled to find help because of the cultural stigma associated with using and drinking.

Nafisa Mohamed met Abdi through that work. He asked her to mentor young, struggling Somali women.

"In our culture, when young women go through certain things like alcohol or drugs, they're usually afraid to talk to people," she said.

After she heard about Abdi's detention, she started preparing herself for the possibility of his deportation. Mohamed began to think of ways she could help him if he was sent back — like finding a safe place to live away from the terrorist group, al-Shabab.

So when she heard Judge Mazzie's decision this week to release Abdi without bail, she was surprised. Abdi was released on his own recognizance, which is rare. He was free a few hours after the hearing.

"I'm really happy to see the system really work," Mohamed said. "Judges don't do that. And it was beautiful that she did that. Other judges just follow a system, and they're like, 'We've never done this before so we're not going to do it and give this person a chance.' ... Usually, when you go through immigration court, it's kind of like a death sentence sometimes. "

Shortly after Abdi's arrest last year, ICE moved him and a group of others to different facilities to get them ready for a flight back to Somalia. But his lawyers got him an emergency stay, meaning temporary relief and the chance to reopen his case.

Abdi has spoken out against terror recruitment and his lawyers say he's received threats from al-Shabab on social media. They argued the emergence of the group made it unsafe for him to return.

An immigration judge ruled in his favor, but the government appealed. The Board of Immigration Appeals upheld the lower court's order. His case was technically final three months ago.

"But there is a provision in the immigration law that allows them to hold people for 90 days after a removal order to look for what's called a safe third country to accept them," said Kim Hunter, one of his attorneys.

"We're really just holding people for 90 days and paying these county jails to hold them to no end," Hunter said. "And so the detention numbers continue to go up because the government continues to take more appeals. Expenses continue to grow. And again, to what end? Particularly when people have demonstrated clearly to the satisfaction of the court that they deserve the right to stay in the United States."

Lawyers say immigration authorities under the Trump administration have gone back to court repeatedly to fight adverse decisions. Overall, deportation numbers in fiscal year 2018 continued to rise, according to an ICE report. Administrative arrests for civil immigration violations are also up.

Abdulkadir Sharif Abdi is greeted by his wife, Rhoda Christenson, and other family and friends outside immigration court in Bloomington Tuesday. Courtesy of Rhoda Christenson

Abdi remained in the holding cell for about five hours after his hearing. He was waiting for officers to move his belongings from the Freeborn County Jail, where he'd been held, to Fort Snelling.

A video shot outside the building shows his family and friends hugging and cheering for him.

But this release order isn't a guaranteed path toward legal status. He still needs to find permanent protection from deportation. In the meantime, he'll be back to Fort Snelling, to check in.