BAGRAM, Afghanistan -- The U.S. military gave control of its last detention facility in Afghanistan to Kabul on Monday, a year after the two sides initially agreed on the transfer.
The handover of Parwan Detention Facility ends a bitter chapter in American relations with Afghanistan's mercurial president, Hamid Karzai, who demanded control of the prison as a matter of national sovereignty.
It took place just a few hours before U.S. Secretary of State John Kerry flew into Afghanistan on an unannounced visit to see Karzai amid concerns the Afghan president may be jeopardizing progress in the war against extremism with anti-American rhetoric.
The dispute over the detention facility fueled acrimony between the two countries in recent months and also threw a pall over the ongoing negotiations for a bilateral security agreement that would govern the presence of U.S. forces in Afghanistan after 2014.
Top U.S. commander in Afghanistan Gen. Joseph Dunford handed over Parwan, located near the U.S.-run Bagram military base north of Kabul, at a ceremony there after signing an agreement with Afghan Defense Minister Bismullah Khan Mohammadi.
"The transfer of the detention facility is an important part of the overall transition of security lead to Afghan National Security Forces. This ceremony highlights an increasingly confident, capable, and sovereign Afghanistan," Dunford said.
An initial agreement to hand over Parwan was signed a year ago, but efforts to follow through on it constantly stumbled over American concerns that the Afghan government would release prisoners that it considered dangerous.
A key hurdle was a ruling by an Afghan judicial panel holding that administrative detention, the practice of holding someone without formal charges, violated the country's laws. The U.S. argued that international law allowed administrative detentions and also argued that it could not risk turning over some high-value detainees to the notoriously corrupt Afghan court system.
An initial deadline for the full handover passed last September and another earlier this month.
The formula for how the two sides resolved this dilemma has not been made public. Officials say that the Afghan government will be able to invoke a procedure that ensures prisoners considered dangerous will not be released from the detention center. According to a senior U.S. official in Washington, the agreement also includes a provision that allows the U.S. and Kabul to work together to resolve any differences. The official lacked authorization to discuss the details of the agreement publicly and spoke on condition of anonymity.
Ashraf Ghani Ahmadzai, who heads the Afghan transition commission and helped broker the deal, said the "transfer is an outcome of a long and sustained dialogue between the government of Afghanistan and the international community. A year ago we reached agreement in principle on the transfer but intense discussion in the last month is culminated in a principled agreement."
He said Karzai had made "transferring authority form international forces to our national forces as a key marker" of his administration.
The detention center houses about 3,000 prisoners and the majority are already under Afghan control. The United States had not handed over about 100, and some of those under American authority do not have the right to a trial because the U.S. considers them part of an ongoing conflict.
There are also about three dozen non-Afghan detainees, including Pakistanis and other nationals that will remain in American hands. The exact number and nationality of those detainees has never been made public.
"They are not the priority of the Afghan government so the Americans can keep them for the time being. Our priority are the Afghan detainees," Afghan Defense Ministry spokesman Gen. Zahir Azimi said.
He added that under the agreement, the U.S.-led military coalition has 96 hours to hand over any new detainees it picks up on the battlefield to Afghan authorities.
A new agreement, or memorandum of understanding, was signed at the ceremony by Dunford and Khan, but the U.S. military said it will not be made public. The agreement supplants one signed last March, which had been made public.
The U.S. military said in a statement that the new agreement "affirms their mutual commitment to the lawful and humane treatment of detainees and their intention to protect the people of Afghanistan and coalition forces," an apparent reference to the release of detainees deemed to be dangerous.
The handover should also open the way for a resumption of talks for a bilateral security agreement that would govern the presence of U.S. forces in Afghanistan after 2014.
It is part of an ongoing effort to gradually shift control of the country's security to the Afghans as the U.S. and allies move toward the full withdrawal of combat troops by the end of 2014.
There are about 100,000 coalition troops in Afghanistan, including about 66,000 from the United States. American officials have made no final decision on how many troops might remain in Afghanistan after 2014, although they have said as many as many as 12,000 U.S. and coalition forces could remain.
The U.S. started to hold detainees at Bagram Air Field in early 2002. For several years, prisoners were kept at a former Soviet aircraft machine plant converted into a lockup.
In 2009, the U.S. opened a new detention facility next door. The number of detainees incarcerated at that prison, renamed the Parwan Detention Facility, went from about 1,100 in September 2010 to more than 3,000.
After Monday's handover, it was renamed the Afghan National Detention Facility at Parwan and the U.S. military said it would provide the Afghan army with advisers and $39 million in funding.
The United States has spent about a quarter of a billion dollars to build the Bagram facility along with Kabul's main prison located in the capital.