US officials reluctantly handed over control of Bagram prison to Kabul today, although it insisted on retaining authority over several inmates.
It sits next to the sprawling US Bagram airbase, just north of Kabul.
President Hamid Karzai hailed the transfer as a victory for Afghan sovereignty.
"Today is a proud day," said Afghan army General Ghulam Farouk, who now heads the prison.
The US had already given Afghanistan authority over most of Bagram's 3,000 prisoners.
The number of inmates still under US control is not known but is thought to be in the hundreds.
The US recently suspended the transfer of new detainees, apparently because of disagreements with Kabul, which has questioned jailing suspects without charge.
The US reportedly fears that the Afghans may simply let some detainees go, and appears reluctant to turn over all the people it holds.
Gen Farouk said the US has transferred 3,082 detainees but was still in the process of transferring another 600.
The US will also continue to hold about 50 non-Afghan prisoners, who are not covered by the agreement, on a small part of the facility that the US will still run.
They are thought to include Pakistanis and other foreign nationals either captured in Afghanistan or transferred to Afghanistan from other wars.
Acting Afghan Defence Minister Enayatullah Nazary said that "very few prisoners" remain with the US military and the rest are in Afghan hands.
He blamed "technical issues" for the delay in handing over the rest.
If you appreciated this article then please consider donating to the Morning Star's Fighting Fund to ensure we can keep developing your paper.
Donate to the Fighting Fund here
A government guided by common sense would respond to news that publicly owned Royal Mail has increased profits to £403 million by scrapping plans to flog off the service.
Wales TUC president sets out the achievements of Welsh workers over the past year - and looks to the battles ahead
Interview with Jeremy Scahill, author of a chilling new exposé of the US's worldwide war without end