WASHINGTON  A federal judge on Tuesday ordered the Bush administration to release 17 detainees at Guantánamo Bay by the end of the week, the first such ruling in nearly seven years of legal disputes over the administration’s detention policies.

The judge, Ricardo M. Urbina of Federal District Court, ordered that the 17 men be brought to his courtroom on Friday from the prison at Guantánamo Bay, Cuba, where they have been held since 2002. He indicated that he would release the men, members of the restive Uighur Muslim minority in western China, into the care of supporters in the United States, initially in the Washington area.

“I think the moment has arrived for the court to shine the light of constitutionality on the reasons for detention,” Judge Urbina said.

Saying the men had never fought the United States and were not a security threat, he tersely rejected Bush administration claims that he lacked the power to order the men set free in the United States and government requests that he stay his order to permit an immediate appeal.