The US military has handed over the last prison under its control in Afghanistan.
The transfer of Parwan Detention Facility to the Afghan government ends a bitter chapter in relations between the two countries.
An initial agreement was signed over a year ago, but there were delays in finalising a deal because of US concerns over the fate of prisoners it considered dangerous.
America used to hold detainees at Bagram Air Base, before opening the Parwan facility nearby in 2009. The number of detainees went up to around 3000.
The handover took place just hours before US Secretary of State John Kerry arrived in Afghanistan on an unannounced visit.
He was due to meet Afghan President Hamid Karzai, amid concerns that the leader maybe jeopardising progress in the fight against extremism with anti-American rhetoric.