Afghan officials have agreed to take over the running of the US military prison at Bagram, which currently houses about 750 inmates, including around 30 foreign nationals.
A so-called Memorandum of Understanding signed on Saturday could see the controversial facility handed over to Afghan control within months, officials said.
"The Afghan defence ministry will begin in a few days to train a unit which will take responsibility for the prison," it said in a statement.
The prison facility, set up to hold enemy suspects in the wake of the US invasion of Afghanistan in 2001, has faced heavy criticism due to the treatment of detainees, drawing comparisons to Guantanamo Bay and Abu Ghraib in Iraq.
The facility has been under scrutiny since two Afghan detainees died after being beaten, deprived of sleep and kept constantly chained at the facility in 2002, leading to prisoner abuse charges against several American troops.
Prisoners held in Bagram are not given lawyers or trials, a practice that Washington was required to end in Iraq last year under an agreement with the Iraqi government.
Washington set up a system last year that allowed Bagram detainees to contest their detention assisted by "personal representatives" from the military who are not lawyers.
The Afghan government has long-sought to have prisoners transferred from foreign military control saying that Afghans should not be held by foreign powers within their own territory.
"President Karzai himself has said detention and prosecution of suspects should be the responsibility of the Afghan government. So that's where this is heading," Colonel Stephen Clutter, spokesman for US military detainee operations in Afghanistan, said.
"This will eventually help Afghanistan strengthen its own security."
Clutter said that Afghan personnel could be working at Bagram from March.
"We haven't put an exact time figure on how long it's going to take to do the transition but it is a very aggressive schedule," he said.
General Mohammad Zahir Azimi, a spokesman for the Afghan defence ministry, said that the handover could take place within six months.
"This is a very good and important step for the Afghan government so it will have responsibility for the Afghan prisoners," he said.
Afghan authorities decided that the ministry of defence would initially assume responsibility for the transition, but will eventually transfer its role as custodian and manager of the facility to the ministry of justice, a US statement said.
Last month, a new $60m facility, named the Parwan Detention Centre after the province where it is located, was opened on the site to replace the original prison that had been housed in a converted aircraft hanger.