The United States will hand over the control of all prisons in Afghanistan to Afghan security forces within six months.

After months of negotiations, the two countries reached a deal on Friday that will transfer all of the 3,000 prisoners in American-run detention facilities to Afghan authorities.

The signing of this memorandum is an important step forward in our strategic partnership negotiations, said General John Allen, the commander of NATO and U.S. forces in Afghanistan, according to the Press Association.

This MOU (Memorandum of Understanding) illustrates our commitment to Afghan sovereignty, U.S. Ambassador Ryan Crocker stated.

The deal comes at a time when relations between the U.S. and Afghanistan are especially tense. Dozens of people were killed in riots following the burning of copies of the Koran at an American base and detention center outside of Kabul last month. This new security pact could do more to restore relations that President Barack Obama's apology for the book burnings.

Afghanistan's Minister of Defense Abdul Rahim Wardak said on Friday that the first group of 500 detainees will be transferred to local authority within 45 days, and the Parwan detention facility, where the Koran burning took place, could be handed over to Afghan security within a day.

The U.S. forces will still have access to Parwan and be able to block the release of prisoners they think should still be held, the Press Association reported. Additionally, the 50 non-Afghans at the facility will remain in American custody.

All American and international troops are scheduled to withdraw from Afghanistan by 2014, but the U.S. wants to leave a small support team behind to help with Afghan security. The two sides have not agreed on a final plan, but the prison transfer was a necessary step in the negotiation process.