Yaser Esam Hamdi, who was held in solitary confinement as an "enemy combatant" for nearly three years and never charged with a crime, will be released from custody and flown home to Saudi Arabia, government officials announced yesterday.

Hamdi, a United States citizen, will leave on a military aircraft, probably by the end of the week, said Frank W. Dunham Jr., the federal public defender representing him. The Justice Department said only that Hamdi's release "is currently being arranged."

The U.S. military captured Hamdi with pro-Taliban forces in Afghanistan in 2001. He was sent to Guantanamo Bay along with other detainees until authorities learned that he was born in Louisiana and was a citizen. He has been held in military brigs ever since.

Hamdi's detention came to symbolize the legal clash over the government's anti-terror efforts. The government convinced a federal appeals court in Richmond that the military -- and not the courts -- had the sole authority to wage war and that courts should defer to battlefield judgments. But in June, the Supreme Court ruled that Hamdi had the right to contest his detention in court.

Now, with his pending release, the mystery of Hamdi, and what threat, if any, he posed to national security may never be resolved.

Some legal experts argued that the deal to release Hamdi means that the government should not have held him for so long in the first place. "This is tremendously embarrassing to the government," said Shayana Kadidal, an attorney with the New York-based Center for Constitutional Rights, which filed legal briefs on Hamdi's behalf.

He added: "This shows that if you don't have judicial review of detentions, then the executive branch can take people who are essentially totally innocent . . . and hold onto him for three years."

But other lawyers said the Hamdi case produced an important legal victory for the government because the Supreme Court ruled that the government still has the authority to detain U.S. citizens as enemy combatants, even if they can challenge the detentions.

"That was a very significant holding,'' said Victoria Toensing, a Washington lawyer and former top counterterrorism official. Toensing said the enemy combatant designation gives the government another legal option in the war on terror.

The Justice Department would not discuss the case except to say that Hamdi is being released because he no longer poses a threat.

"The United States has determined that Mr. Hamdi could be transferred out of United States custody subject to strict conditions that ensure the interests of the United States and our national security," spokesman Mark Corallo said in a statement. "As we have repeatedly stated, the United States has no interest in detaining enemy combatants beyond the point that they pose a threat to the U.S. and our allies."

Government attorneys had justified Hamdi's detention with a Defense Department declaration that he had joined a Taliban military unit, received training and acknowledged loyalty to the Taliban.

Dunham said he takes issue with the Justice Department's description of Hamdi as an enemy combatant. "They may think he is an enemy combatant, but not in the way Justice O'Connor described it," he said, referring to the Supreme Court opinion by Justice Sandra Day O'Connor.

Dunham said he is "gratified that the prospect of Mr. Hamdi's return to Saudi Arabia and to his family is now only days away." Although Hamdi was born in Baton Rouge, he has spent most of his life in Saudi Arabia, where his family lives.

The Supreme Court opinion, in which all the justices except Clarence Thomas rejected the Bush administration's contention that the courts could exercise no supervision over Hamdi's case, laid the groundwork for negotiations to release him. The agreement was finalized late last week.

The military designated Hamdi an enemy combatant and held him incommunicado and without a lawyer for much of his time in custody. He is one of two U.S. citizens held as enemy combatants since the Sept. 11, 2001, terrorist attacks; the other is Jose Padilla, who is accused of plotting to set off a radiological bomb in the United States.

The release agreement requires Hamdi, once in Saudi Arabia, to renounce any claim to U.S. citizenship and to abide by strict travel restrictions, according to the Justice Department statement. Sources familiar with the agreement said it restricts Hamdi from leaving Saudi Arabia for a certain time and restricts him from traveling to the United States, Afghanistan, Iraq, Israel, Pakistan, Syria, the West Bank and the Gaza Strip.