Afghanistan is set Monday to take full control of Bagram military jail from the United States, drawing a line under one running sore in their relationship as US-led forces wind down more than a decade of war.
President Hamid Karzai has made the fate of the sprawling detention centre north of Kabul a litmus test of his ill-tempered push to regain sovereignty over key matters from the Americans ahead of next year's pullout of combat troops.
The United States was long concerned that a total handover to Afghanistan's weak and corruption-prone security forces would allow suspected Taliban and Al-Qaeda militants housed at Bagram to return to the battlefield.
But US Secretary of Defense Chuck Hagel clinched an agreement with Karzai in a telephone call on Saturday, and the handover will take place on Monday, the Pentagon said. No further details were given.
Bagram was already due to be turned over to Afghan forces on March 9, but the transfer was postponed at the last minute after comments from Karzai that "innocent" prisoners held at the facility would be released.
In September, the United States gave Afghan authorities control of more than 3,000 detainees at Bagram, once dubbed the Guantanamo Bay of Afghanistan because some inmates are detained without trial or knowledge of any charges.
But the Americans continued to guard 50 foreigners not covered by the agreement, as well as hundreds of Afghans arrested since a transfer deal was first signed in March 2012.
Their extended control sparked angry outbursts from Karzai and a warning from Afghanistan's top Islamic body that the US military was coming to be seen as an "occupation" force as it battles a long-running Taliban insurgency.
Karzai, who leaves office next year, has also long been chafing at the activities of US special forces and at civilian casualties. He recently triggered outrage by accusing the US of colluding with the Taliban to justify the presence of foreign troops.
Last week he won a limited agreement for Afghan forces to take charge of one district of Wardak province, a key front of the insurgency pitting insurgents against the the US-led International Security Assistance Force (ISAF).
The agreement made no mention of Karzai's demand for US special forces to withdraw entirely from Wardak, and ISAF said that it was "business as usual" for its troops in the rest of the flashpoint province.
Afghan army and police are gradually taking on responsibility for battling the Taliban insurgency as most of the 100,000 foreign troops prepare to exit by the end of next year under a timetable laid down by US President Barack Obama.
Karzai is due to step down at elections next year, 13 years after he came to power with US backing when the hardline Taliban regime was ousted in the aftermath of the September 11 attacks of 2001.
The military drawdown is lending added urgency to the search for a political settlement to resolve Afghanistan's decades of conflict.
Karzai plans to visit Qatar "within weeks" to discuss the proposed opening of a Taliban office in the Gulf emirate as a prelude to possible peace talks, the Afghan foreign ministry said Sunday.
Until earlier this year, Karzai rejected the idea of a Taliban office in Qatar because of fears that his government would be frozen out of any deal between the US and the militants.
The Taliban have refused to negotiate directly with Karzai, and the foreign ministry stressed that it would only start negotiations if the militants "break all relations with Al-Qaeda and give up terrorism".