The United States on Monday ceded full control of the Bagram prison, the main US detention facility in Afghanistan, to local forces, possibly removing a thorn in the two countries’ frayed relations.

The US was supposed to fully hand over the facility, which holds more than 3,000 Afghan prisoners and about 50 foreigners, last September. But the transfer was postponed after President Hamid Karzai indicated that “innocent” prisoners would be freed.

A final agreement was sealed on Saturday, and a handover ceremony was held at the jail, now known as Parwan Detention Facility, reports AFP.

General Joseph Dunford, commander of the international coalition, and Defence Minister Bismilliah Mohammadi signed a deal guaranteeing the treatment of detainees and “to protect the people of Afghanistan and coalition forces.”

Mohammadi hailed the transfer as “a crucial and positive step towards the security and self-sufficiency of Afghanistan.”

Washington has long expressed concerns that a total handover to Afghanistan’s relatively weak and corruption-prone security forces would yield to Taliban insurgencies.

The handover comes as US Secretary of State John Kerry arrived unannounced in Kabul despite Karzai’s increasingly antagonistic stance towards Washington.

“We are committed to an enduring partnership… The US supports a strong and united Afghanistan,” Kerry said at a press conference in Kabul.

“We are committed to Afghanistan’s sovereignty and we will not let Al Qaeda or the Taliban shake this commitment.”

Afghan troops and police are gradually taking on responsibility for battling the Taliban as most of the 100,000 foreign troops prepare to exit by the end of 2014.