A federal judge yesterday ordered the government to produce "enemy combatant" Yaser Esam Hamdi at a federal court hearing later this month in Norfolk if prosecutors and Hamdi's attorneys fail to reach a deal to free him.

The two sides had asked U.S. District Judge Robert G. Doumar last week to stay all proceedings for 21 days while negotiations continue over Hamdi's likely release from custody. Hamdi has been held incommunicado in a Navy brig for two years.

Doumar granted the motion but gave the parties two days fewer than they had asked for, setting a hearing for Aug. 30 if the case is not dismissed by then.

If Hamdi were to appear in a federal courtroom to contest his detention, it would mark a milestone in the war on terrorism. Neither of the two U.S. citizens held as enemy combatants after the Sept. 11, 2001, attacks, Hamdi and Jose Padilla -- who is accused of plotting to set off a radiological bomb in the United States -- has been seen publicly since being detained.

Hamdi has been jailed since he was captured with Taliban soldiers in Afghanistan in 2001, and his case has come to symbolize the conflicting arguments over whether the military has sole authority to wage anti-terror efforts or whether courts can intervene.

The Bush administration refused to allow Hamdi to challenge his detention and has held him for much of the past two years without access to a lawyer. But in June, the Supreme Court ruled that as a U.S. citizen, Hamdi must have access to the U.S. legal system.

Frank W. Dunham Jr., the federal public defender representing Hamdi, said he is "still optimistic" that a deal will be reached to free him. But Dunham said it's unclear whether that will be accomplished by the judge's deadline because some government officials who would need to sign off are on vacation.

"Whether we can get this done by the 30th or not won't be because of any disagreements; it would just be logistical problems," he said.

A Justice Department official said the negotiations are ongoing. "We're working to see whether we can satisfy our national security concerns and reach an agreement to settle the litigation," said the official, who requested anonymity because of a department policy about commenting on pending cases.

People familiar with the negotiations have said the terms of Hamdi's potential release are likely to include that he renounce his U.S. citizenship, move to Saudi Arabia and accept travel restrictions, as well as some monitoring by Saudi officials. In addition, he may have to agree not to sue the federal government over whether his civil rights were violated.

Terrorism experts have called the negotiations an embarrassment to a government that had strongly insisted that Hamdi was a threat and must be held. But government officials have said that there is precedent for the conditional release of prisoners in wartime and that Hamdi could be freed if he has no further intelligence value and is no longer considered a threat to national security.

Hamdi was captured alongside pro-Taliban forces on the battlefield in northern Afghanistan in November 2001 and taken to the U.S. military prison at Guantanamo Bay, Cuba. He was brought to the Navy brig in Norfolk and then the Navy jail at Charleston, S.C., after it was learned that he was born in Baton Rouge, La.

Designated an enemy combatant by the military, Hamdi was held incommunicado. But his case entered the legal system after Dunham read about his confinement in news accounts. The Bush administration reversed itself in December and said that Hamdi could see a lawyer because his intelligence value had been exhausted and that giving him a lawyer would not harm national security.

Then came the Supreme Court ruling, in which all the justices except Clarence Thomas rejected the Bush administration's contention that the federal courts could exercise no supervision over such a case.

"We have long since made clear that a state of war is not a blank check for the President when it comes to the rights of the Nation's citizens," Justice Sandra Day O'Connor wrote for the court's majority.

Defense attorneys and government lawyers have until Aug. 30 to reach an agreement to free Yaser Esam Hamdi.

Judge Robert G. Doumar

set an Aug. 30 court date.