The federal government on Tuesday evening released a Powder Springs man who was suing for his freedom from an immigration detention center in South Georgia.

Juan Carlos Ruiz-Arenas had filed a habeas corpus petition in a federal court, arguing his nearly five-month-long confinement had harmed his mental health and caused him to have seizures.

The Mexican national also argued the government was violating his constitutional rights with cruel and unusual punishment at the Stewart Detention Center near Lumpkin. The detention center placed him on antidepressants and antipsychotic drugs and held him in solitary confinement on two occasions for a total of 18 days. A federal judge had ordered the government to bring Arenas to a court hearing in Columbus on the matter Wednesday afternoon.

U.S. Immigration and Customs Enforcement issued a statement by email, saying the agency decided to release Arenas for “humanitarian concerns.”

“After taking into account a number of factors, including his lack of criminal history and humanitarian concerns, ICE has chosen to exercise prosecutorial discretion and release Mr. Ruiz from custody on his own recognizance,” ICE said in its statement.

ICE officials previously said they were detaining him because of his “long history of disregard for U.S. immigration law.” Even though he has been released from detention, Arenas remains in deportation proceedings. He has illegally entered the country numerous times.

ICE officials said they isolated him from other detainees at Stewart once for “medical observation” and once at his own request for protection, though he denies he ever asked to be segregated.

Arenas, who is married to a U.S. citizen, has been confined since October, when he was arrested for driving without a license in Woodstock. He is fighting deportation to Mexico, where he fears he will be hunted by drug gangs because of his past work as a police officer there. Arenas, who says he has been beaten and shot at by the violent Zetas cartel, has established a “reasonable fear of persecution” in his native country, the government concluded in a January report.

Arenas’ attorneys welcomed the government’s decision to release him Tuesday, saying it is the humane thing to do.

“We are looking forward to getting the treatment our client needs so he can adequately defend himself in immigration court,” said Charles Kuck, one of Arenas’ attorneys.