Image caption The US has previously handed over responsibility for a few hundred detainees at Bagram

Afghanistan and the US have reached a deal to transfer US-run prisons in the country to Afghan control.

The largest and most controversial of these is Bagram jail, which holds 3,000 detainees, including terror suspects.

Under the deal the US will cede control of Bagram over six months. Reports say they will retain access and be able to block the release of certain detainees.

Handing over US-run jails has been a key demand of Afghan President Hamid Karzai ahead of Nato's withdrawal.

Analysts say the issue has cast a shadow over negotiations on Nato's withdrawal of all of its combat forces by the end of 2014 and the long-term relationship with Afghanistan.

Bagram prison, officially known as the Parwan Detention Centre, is located in one of the largest military bases for Nato-led forces in Afghanistan. It has been at the centre of a number of prisoner abuse allegations in recent years.

Nato is also under intense pressure after days of protests and targeted killings across Afghanistan - over the inadvertent burning of Korans at Bagram - left at least 30 people dead.

The US repeatedly apologised over the incident but that failed to quell public anger.

Ongoing US support

Correspondents say the deal is the first stage of a mechanism which is still being worked out but will eventually see US-run jails handed over to full Afghan control.

Analysis US military officials in Kabul told the media that the Afghan government would take charge of about 500 prisoners at the detention centre within 45 days. There are some 3,000 Afghan and 50 non-Afghan prisoners there. US mentors will continue to provide a logistical support role to their Afghan counterparts. But observers say serious concerns remain over the Afghan government's ability to secure its prisons. They cite two major jail breaks in Kandahar last year, which resulted in the escape of hundreds of Taliban leaders and commanders. Analysts say rampant corruption in the government, poor training and low morale in the security forces have made the task of securing prisons even more difficult. Along with night raids, the transfer of detention facilities has been a major stumbling block in negotiations.

The Memorandum of Understanding (MOU) signed by the US and Afghanistan comes after the US missed a deadline Mr Karzai set in January to hand over such jails.

He then gave the US another month to reach an agreement - that deadline was set to expire on 10 March.

On signing the agreement, Gen John Allen, Nato's commander in Afghanistan lauded it as " yet another example of the progress of transition".

Under the terms of the agreement, the US would provide support and advice to the Afghan commander at Bagram for up to a year.

"This MOU illustrates our commitment to Afghan sovereignty, our mutual obligations under international law, and our enduring partnership," a statement released by the US embassy reads.

"We have had our challenges and there will be challenges ahead as we continue negotiation on the framework for our strategic partnership, but this MOU marks an important step forward," it says.

The US has previously handed over responsibility for about 300 detainees at Bagram but said the Afghan government was not ready to fully take control of the prison, the Associated Press news agency reports.