Afghanistan's President Hamid Karzai speaks during the opening ceremony of the third year of the Afghanistan parliament in Kabul on March 6, 2013. (Mohammad Ismail/Reuters)

After weeks of lambasting the United States for its willfulness in Afghanistan, President Hamid Karzai reached an agreement with U.S. forces Wednesday over their withdrawal from Wardak province, on the western outskirts of Kabul.

Karzai and Gen. Joseph F. Dunford Jr., the top U.S. commander in Afghanistan, announced that American troops would gradually pull out of Wardak, along with U.S.-­trained Afghan Local Police (ALP) units.

No timeline has been set for the transition, but it will begin with the embattled Nerkh district, where several insurgent groups, including the Taliban, are known to operate.

Afghan army units will replace coalition troops in Nerkh “in the coming days,” Gen. Zahir Azimi, a spokesman for the Afghan Defense Ministry, said at a news conference Wednesday in Kabul. He expressed confidence in the ability of Afghan troops to fill the gap.

The agreement, nearly a month in the making, “continues the transition of this critical province and meets the security needs of the people and the requirements of our mission,” Dunford said.

Karzai has accused U.S. Special Forces in Wardak of harassing and even torturing civilians, as well as training Afghan police units that he has likened to unruly militias. U.S. officials deny the accusations.

Although Karzai’s critique focused on Wardak, which is considered a key gateway to Kabul, he has also been adamant that foreign troops leave Afghan villages across the country.

The agreement appears to fulfill Karzai’s requirements, though it marks a step back from his demand last week that all U.S. Special Forces troops leave Wardak. U.S. officials said the phased withdrawal was a more responsible approach than an abrupt departure.

But Afghan commanders in Wardak expressed concern that the province would be more difficult to secure without U.S. Special Forces and their Afghan trainees.

“These are troops who have helped us accomplish our missions for years. Why would we force them to leave?” said a senior Afghan military official, who spoke on the condition of anonymity because he was not authorized to discuss the issue publicly.

U.S. officials, including Dunford’s predecessor, Gen. John R. Allen, have long praised the role played by the Afghan Local Police, a security force made up of local recruits. The ALP is due to expand nationwide, according to NATO officials, but Karzai has consistently expressed concern about the force’s growth.

If the ALP is forced to leave Wardak, it would constitute Karzai’s most significant blow to an organization that Allen once called “an important mechanism for holding the ground in Afghanistan.”

Still, Afghan officials pointed to the agreement as a sign that Afghan forces are moving ahead to independently secure even the most strategically important regions of the country.