MINNEAPOLIS (AP) — A federal judge in Minnesota has ruled that an Iraqi man who has been in immigration custody for two years must be released while he awaits a final order for removal from the U.S.

Thirty-five-year-old Farass Adnan Ali has been in consecutive immigration detention since July 2017. U.S. District Judge David Doty ruled Tuesday that the lengthy detention violates Ali’s constitutional rights. Ali must be released within 30 days.

READ MORE: After Long Immigration Detainment, Iraqi Man Seeks Release

The U.S. Department of Justice can appeal. A spokesperson didn’t immediately return a message seeking comment.

Doty says Ali’s current detention is based entirely on the attorney general’s discretion. While the government had said Ali was a national security threat, he hasn’t been designated as a terrorist.

Ali’s attorney Ian Bratlie says the decision is a reminder that immigrants have rights and the judiciary will protect them.

(© Copyright 2019 The Associated Press. All Rights Reserved. This material may not be published, broadcast, rewritten or redistributed.)