The accord, which will see authority over the prison transferred gradually over six months, was inked by Afghan Defence Minister Abdul Rahim Wardak and the US commander in Afghanistan, General John Allen, at a signing ceremony.
The handover of the prison, sometimes called Afghanistan's Guantanamo Bay has been a key sticking point in talks between Washington and the Afghan government on concluding a long-term strategic partnership treaty.
Karzai has repeatedly demanded in the name of Afghan sovereignty that the prison and its 3,000 inmates be transferred before he signs any deal governing Afghan-US relations after Nato combat troops pull out in 2014.
"This is an important step in the strategic partnership negotiations," Allen said at the signing ceremony.
Wardak said the transfer process would take place over six months.
"With the handover of the Bagram prison, one of the conditions of the Loya Jirga will be implemented. We are feeling very proud about this important step," Wardak said.
Human rights campaigners have regularly criticised the prison, saying it fails to comply with international norms as some inmates are detained arbitrarily without trial or knowledge of the charges against them.
The prison, just outside the Bagram airbase north of Kabul, holds rebel fighters detained by US-led Nato forces in their 10-year war against the Taliban-led insurgency trying to topple Karzai's government.
Bagram base was the site of the burning of the Holy Qurans last month which ignited days of violent anti-US protests in which some 40 people died, plunging relations between foreign forces and their Afghan allies to an all-time low.
The Holy Qurans, which were sent to an incinerator pit, had reportedly been seized from prisoners who were suspected of using them to pass secret messages.
News of the deal, initially said to involve "detention facilities" but no temporary holding centres run by the United States, came shortly after Karzai and President Barack Obama spoke by video conference Thursday.
"The leaders noted progress toward concluding a strategic partnership that reinforces Afghan sovereignty while addressing the practical requirements of transition," said White House spokesman Jay Carney.
One other major condition Karzai has set before signing a treaty on long-term partnership is an end to night raids by US-led special forces, which target Taliban leaders in their homes.
The United States says they are a vital element in the anti-Taliban campaign, but the Afghan government says they violate the sanctity of families in their own homes and cause civilian casualties.
In an apparent reference to this, Wardak said: "In the next few days we will continue talks with the US side and finalise another important issue which is Afghanistan of special operations."
In early January, Karzai gave the United States a one-month deadline to hand over the prison, later extending it to March 10.
The prison was built within the sprawling US military base at Bagram after the 2001 US-led invasion toppled the Taliban, and in the early years gained a reputation for extra-judicial brutality.
A new prison called the Parwan Detention Facility was constructed outside the base in 2009, but Afghan authorities still use the old name.
COMMENTS (4)
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ
@Afghan Karachiti: Don't worry sooner or later Taliban kick there A$$ out and then we all know who will really control :)
@kala_bacha:
Better the MOSAD/RAW than ISI (if the Taliban come back).
Congrats, Mr. Karzai. This is really a significant achievement of the Afghan government and a way forward for the upcoming transition. Hope, the charge of special ops and night raids are also taken by the Afghan Special Operation Forces (ASOF).
The heading should be like this " The US sign a deal to hand over the airbase to RAW/ MOSAD"