Afghans held in U.S. military custody at Guantanamo Bay (search) and elsewhere will be sent back to Afghanistan to be detained here, Afghan and U.S. officials said Thursday.

Hundreds of Afghans are being held at the U.S. military prison at Guantanamo Bay, Cuba, and at other American detention facilities. Afghanistan's U.S.-backed President Hamid Karzai (search) has long urged Washington to send them home.

"Afghanistan and the United States reached an understanding that will allow for the gradual transfer of Afghan detainees to the exclusive custody and control of the Afghan government," a joint statement by the U.S. Embassy and the Afghan government said.

"The government of Afghanistan will accept responsibility for the returning Afghan citizens and will work to ensure that they do not pose a continuing threat," it added.

Karzai's spokesman, Karim Rahimi, said the agreement meant that all Afghans held at Guantanamo and elsewhere would be handed over to the government.

"This includes all detainees that are with the U.S. forces," he told The Associated Press.

Pentagon spokesman Bryan Whitman said Thursday that the U.S. military is holding roughly 110 Afghans at Guantanamo Bay and 350 more at a detention center in Bagram, who could be transferred to the control of the Afghan government.

The statement gave no timeframe for the repatriation. U.S. Embassy spokesman Lou Fintor said it would start as soon as the Afghan government has the capacity to detain them.

"The United States intends to assist the government of Afghanistan in building its capacity to detain these individuals," he said. "This process is part of our ongoing efforts to transfer detainees to their home countries as appropriate and when we receive assurances that the country can and will take appropriate steps to ensure that these individuals do not pose a continuing threat."

He said the decision was taken after U.S. ambassador-at-large for war crimes, Pierre-Richard Prosper, and Matthew Waxman, the Pentagon's deputy assistant secretary of defense for detainee affairs, met Karzai on Thursday.

American and allied Afghan forces captured thousands of suspected Taliban and Al Qaeda members in Afghanistan after a U.S.-led invasion toppled the repressive Taliban government in late 2001. Hundreds of detainees were classified as "enemy combatants" and transferred to Guantanamo.

Many have since been returned home and U.S. officials say about 520 detainees, from Afghanistan and elsewhere, are still there.