The U.S. military and the Afghan government sealed an agreement Friday on the gradual transfer of control of the main U.S. prison in the country, a last-minute breakthrough that brings the first progress in months in contentious negotiations over a long-term partnership.

The compromise deal came on the day Afghan President Hamid Karzai had set as a deadline for the Americans to hand over the Parwan prison.

The agreement gives the U.S. six months to transfer Parwan's 3,000 Afghan detainees to Afghan control. However, the U.S. will also be able to block the release of prisoners, easing American fears that insurgents or members of the Taliban could be freed and return to the fight.

The deal removes a sticking point that had threatened to derail talks that have been going on for months that would formalize the U.S.-Afghan partnership and the role of U.S. forces in Afghanistan after NATO's scheduled transfer of security responsibility to the Afghan government at the end of 2014.

On Thursday, U.S. President Barack Obama and Karzai discussed the stalled security pact talks in a video conference. White House press secretary Jay Carney said the two leaders noted progress toward completing an agreement "that reinforces Afghan sovereignty while addressing the practical requirements of transition."

Contentious night raids

Another major sticking point in the negotiations remains unresolved: night raids by international troops on the homes of suspected militants. Karzai has demanded a halt to the raids, which have caused widespread anger among Afghans.

U.S. and Afghan officials have said that they want a strategic partnership agreement signed by the time a NATO summit convenes in Chicago in May.

Gen. John Allen, the commander of U.S. and NATO forces in Afghanistan, called Friday's deal a sign of real progress toward the larger partnership accord.

"This is an important step. It is a step forward in our strategic partnership negotiations," Allen told reporters in the capital before signing the agreement alongside Afghan Defence Minister Abdul Rahim Wardak.

The deal gives the Americans the extension they wanted for Parwan, a U.S.-run prison adjoining its Bagram military base north of Kabul, but also spells out an American commitment to a firm transfer date for the first time. Previously, the U.S. has always offered "target dates" rather than deadlines.

si-parwan-00478433

A U.S. military guard watches over detainee cells inside the Parwan detention facility near Bagram Air Field in Afghanistan in this March 2011 photo. (Dar Yasin/Associated Press)

Under the deal, an Afghan general will be put in charge of Parwan within days, but the Americans have a six-month window to transfer detainees to Afghan oversight, according to presidential spokesman Aimal Faizi.

The U.S. military will still be able to monitor operations. It will continue to provide logistical support for 12 months, and a joint U.S.-Afghan commission will decide on any detainee releases until a more permanent pact is adopted, according to U.S. officials involved in the negotiations — a setup that will essentially give U.S. officials power to veto any release. The Afghans also have agreed to grant human rights groups regular access to detainees. Last year, the United Nations found evidence of torture at a number of Afghan-run prisons.

The officials, who spoke anonymously to discuss confidential talks ahead of the signing, said the first 500 detainees are expected to be transferred in 45 days. The U.S. government had already handed over a few hundred detainees to the Afghans before the agreement was signed.