A federal judge has ordered the release of a man swept up during a chaotic Chinatown immigration raid last fall, ruling that Immigration and Customs Enforcement failed to follow its own rules — and criticizing the agency’s claim of broad stop‑and‑detain authority.

The ruling stems from an ICE operation along Canal Street last October when two dozen federal agents descended on the strip, best known for its knock-off goods, and began restraining several individuals. Protestors and other bystanders soon began clashing with law enforcement officials.

At least four people were arrested, among them Mamadou Boucom Ndoye, a Malian national who had been living in the United States for more than 15 years. Though a final order of removal had been issued for Ndoye, he had been allowed to stay in the country under a federal “Order of Supervision.”

After his arrest, though, ICE revoked that order and jailed him — a move U.S. District Judge Vernon Broderick ruled violated Ndoye’s due process rights. Ndoye represented himself in the case and the ruling came in response to a writ of habeas corpus filed by his wife while he was being held in Goshen at the Orange County Correctional Facility.

In his decision, Broderick, an Obama appointee, ruled that ICE illegally detained Ndoye by ignoring its own regulations. Under the agency’s rules, only certain senior officials are allowed to revoke an Order of Supervision, but in Ndoye’s case that decision came from a lower-level officer without proper authority.

Though the ruling was narrow, Broderick didn’t hold back in his assessment of ICE’s conduct in the case.

During an earlier hearing, the government had argued that it could “check identification of anyone they encounter,” but Broderick disagreed, noting he was unaware of any case law granting “ICE carte blanche to check the identification of or detain anyone they see fit.”

The judge further raised questions about the agency’s account of how Ndoye was identified and arrested in the first place. ICE presented no warrant, Broderick wrote, nor did it offer any probable cause for the arrest or proof “the arrest was, in fact, anything more than ‘happenstance.’”

The lack of clarity, the judge wrote, is why regulations exist in the first place.

“Absent such procedures, the agency will be free to either engage in preplanned decisions to unlawfully detain individuals and then come up with post hoc rationalizations,” he wrote, “or merely randomly stage ‘encounters’ without the intent to unlawfully detain individuals and then create post hoc rationalizations for these unlawful detentions.”

Broderick ordered ICE to release Ndoye “as soon as possible” and transport him back to New York City.

The Department of Homeland Security did not immediately respond to a request for comment.