American military officials have steadfastly denied the Afghan abuse allegations, which led the president, Hamid Karzai, to demand the withdrawal of the US commandos from Wardak province despite fears the decision could leave the area and the neighbouring capital of Kabul more vulnerable to al-Qaida and other insurgents.

The agreement calls for the US-led coalition to withdraw the special operations forces from Wardak's Nirkh district, the area where the abuses allegedly occurred, along with the Afghan forces who work with them, as they are replaced by the Afghan army or national police. The rest of the province would "transition over time," according to a statement.

It was a symbolic victory for Karzai, who has long complained that US special operations forces and their Afghan partners are outside his control. It will also speed the handover of security in the troubled province, faster than US officials and some members of Karzai's government had recommended or planned.

An Afghan defence ministry spokesman, General Zahir Azimi, said Afghan forces were ready to fill the gap.

"The international forces are ready to withdraw the special forces from Nirkh district of Maidan Wardak province, and Afghan army units are going to replace them in the coming days," Azimi said at a press conference in Kabul on Wednesday.

He said there were no other US commando units elsewhere in the province.

A US military official confirmed that, saying that a small, mostly US army special operations team and the Afghan troops working with them would withdraw from Nirkh.

The deal took more than three weeks for US and Afghan security officials to craft, more than a week after the expiration of the deadline for the US pullout initially set by Karzai.

The pace "is really driven by a requirement to have effective security – not just for us, it's for the Afghans as well," Dunford said in an interview with Associated Press on Monday.

Speaking before the announcement of the deal, Karzai's spokesman, Aimal Faizi, said Afghan security forces would take control of the province eventually, so the gradual transfer "can be a testing period."

Faizi insisted this week that an Afghan-American man working for the US special operations forces had been filmed abusing a suspect, on US orders. The spokesman said the video had been obtained during an Afghan defence ministry investigation, which was completed over the weekend.

Dunford rejected the abuse charge in Monday's interview. He said a recently completed US investigation had found that the interpreter was not working with US forces at the time of the incident.

"We've investigated this three times, so I'm confident," Dunford said. "There were no US forces in or around that incident, and the interpreter was not in our employ at the time of the incident."

It was not clear what the agreement would mean for dozens of small US special operations outposts throughout Afghanistan, and the Afghan units partnered with them.

The posts are intended to help extend security and Afghan government influence to remote Taliban strongholds that are beyond the range of the Afghan army or police. American commandos partner with small bands of Afghan local police or "ALP," a force that was created by the US and later incorporated into the Afghan interior ministry. While the units work with Americans, they answer to the local district police chief, according to an Afghan security official who spoke on condition of anonymity.

To join the local police, potential recruits, all drawn from the local villages, must be vouched for by local elders then vetted by the interior ministry, including a background check by Afghan intelligence to rule out prior participation with the Taliban. If approved, they get rudimentary training on weapons safety and basic police skills and military tactics.

Afghan and coalition officials say the back-country policemen have so eroded militant influence that they have become a top target for the Taliban. Bounties for individual policemen are $6,000 (£4,000), compared with $4,000 for regular policemen and $2,000 for Afghan soldiers, one Afghan official said.

But Karzai's national security council has delayed an interior ministry request to recruit and train another 45,000 local police. Karzai believes the units are "outside his control", Faizi said, adding that some members have been caught preying on locals with impromptu checkpoints or abusing the civilians under their care.

US and Afghan officials point out that the Afghan interior ministry handed over five local police accused of rape for prosecution last year. The men were given lengthy jail sentences. But the UN mission to Afghanistan says accountability among the units is uneven, varying from province to province.

"As with any programme, there have been challenges," said the Washington-based Rand Corp analyst Seth Jones, who was on the team that helped set up the programme. "Some [units] are better than others. One key question over the long run is: How effective will the Afghan ministry of interior and Afghan forces be in running the ALP programme without US forces assisting in villages? It's unclear at this point."

Also on Wednesday, police in southern Afghanistan opened fire on a crowd protesting at the alleged desecration of the Qur'an by a member of the local police force, the provincial governor's spokesman, Ahmad Zarak, said, adding that four civilians were killed.

He said the police were responding to fire from a militant who was hiding in the crowd in the Musa Quala district of Helmand province.

Obaidullah Jan, one of the protesters, told AP that the demonstrators did not fire at all but the police opened fire when the crowd reached 100 metres from their position.