Yet, he continued, the Supreme Court has repeatedly held that Congress and the executive branch, in exercising their broad power over naturalization and immigration, can make rules that would be unacceptable if applied to American citizens.

In the judge's view, the government has the right to detain people indefinitely as long as their eventual removal is "reasonably foreseeable." If that interpretation stands, it could apply to millions of noncitizens, including tourists removable for visa violations, said Gerald L. Neuman, a law professor at Columbia who is an expert in human rights law and was not involved in the case.

"It doesn't seem to limit the motives the government has to have in being slow in removing them; it could even be just basic neglect," he said.

But Professor Neuman cautioned that "it's only a district judge's decision."

"The decision encourages the government to behave this way without fear of financial liability," he said, but it does not carry the weight of a ruling by an appellate court. "This interpretation is attackable even among other judges in Brooklyn, let alone Lower Manhattan."

But David Cole, a law professor at Georgetown University and a co-counsel in the lawsuit, said the ruling was the only one of its kind and made New York "an equal protection-free zone" because the government can detain immigrants wherever it chooses.

"What this decision says is the next time there is a terror attack, the government is free to round up every Muslim immigrant in the U.S., based solely on their ethnic and religious identity, and hold them on immigration pretexts for as long as it desires," he said. "We saw after 9/11 what the government did in an era of uncertainty about how far it can go. Judge Gleeson has essentially given them a green light to go much further."

The class-action lawsuit, Turkmen v. Ashcroft, is the first and largest of several brought by immigrants held after 9/11. The named plaintiffs in the case include former detainees who came back to the United States this year for depositions and were required to be in the custody of federal marshals at all times. Among them were Hany Ibrahim, a deli worker, and his brother, Yasser, a Web designer, Egyptian Muslims who said then that putting themselves back in the hands of the government they were suing was an act of faith in America.