The United States on Friday signed a deal transferring the controversial Bagram prison to Afghan control, marking a breakthrough in negotiations over a strategic treaty between the two nations.
The handover of the US-run prison -- sometimes called Afghanistan's Guantanamo Bay -- has been a key sticking point in talks between Washington and the Afghan government on concluding a long-term partnership pact.
Afghan President Hamid Karzai has repeatedly demanded in the name of Afghan sovereignty that the prison and its 3,000 inmates be transferred before he signs any deal governing Afghan-US relations after NATO combat troops pull out in 2014.
That treaty would likely cover the legal status of US troops remaining in the country to help Kabul with intelligence, air power and logistics in the fight against Taliban insurgents.
In Iraq, Washington abandoned its pursuit of a strategic partnership deal and pulled out all its troops, leaving no residual force, after failing to get Baghdad to grant its soldiers legal immunity.
"This is an important step in the strategic partnership negotiations," the US commander in Afghanistan, General John Allen, said at the signing ceremony on the prison deal.
Afghan Defence Minister Abdul Rahim Wardak said the accord would see authority transferred gradually over six months.
"With the handover of the Bagram prison, one of the conditions of the Loya Jirga (grand assembly of Afghan elders) will be implemented. We are feeling very proud about this important step," Wardak said.
The prison, outside the Bagram airbase north of Kabul, holds rebel fighters detained by US-led NATO forces in their 10-year war against the Taliban-led insurgency trying to topple Karzai's government.
Under the agreement, Afghan authorities will need to advise the US of plans to release any prisoners and "consider favourably" objections if the Americans consider such inmates could engage in "terrorist activity".
The US would also maintain a presence at the prison to provide advisory, technical and logistical support for a year.
In turn, the Afghans would give the US and humanitarian bodies access to detainees to monitor their treatment under international humanitarian law.
Human rights campaigners have regularly criticised the prison under US control, saying it fails to comply with international norms as some inmates are detained arbitrarily without trial or knowledge of the charges against them.
The Bagram base was the site of the burning of Korans last month which ignited days of violent anti-US protests in which some 40 people died, plunging relations between foreign forces and their Afghan allies to an all-time low.
The Korans, which were sent to an incinerator pit, had reportedly been seized from prisoners who were suspected of using them to pass secret messages.
A prison was originally built within the sprawling US military base at Bagram after the 2001 US-led invasion toppled the hardline Islamist Taliban regime for sheltering Al-Qaeda leader Osama bin Laden.
The new prison officially called the Parwan Detention Facility was constructed outside the base in 2009, but Afghan authorities usually still use the old name.
One other major condition Karzai has set before signing a treaty on a long-term partnership is an end to night raids by US-led special forces, which target Taliban leaders in their homes.
The United States says they are a vital element in the anti-Taliban campaign, but the Afghan government says they violate the sanctity of families in their own homes and cause civilian casualties.
In an apparent reference to this, Wardak said: "In the next few days we will continue talks with the US side and finalise another important issue which is Afghanisation of special operations."