The White House rejected as "categorically false" a claim by Afghan president Hamid Karzai that the US was effectively colluding with the Taliban in maintaining violence to prolong America's presence in the country.

Karzai's outburst on Sunday, while new US defence secretary Chuck Hagel was making his first visit to the country, highlighted tensions between Washington and the Afghan government as Nato forces withdraw from the country and negotiations continue over the number of troops to be left behind after 2014.

The White House response to Karzai's latest criticism of the US came as an Afghan dressed in a police uniform opened fire in the disputed Wardak, province killing two US soldiers and at least two Afghans.

One of the Americans killed was a special forces operative from the Green Berets, CNN reported.

Karzai had set Monday as the deadline for the withdrawal of all US special operatives from Wardak province after allegations of abuse, but the US has so far refused.

At the daily White House briefing on Monday, press secretary Jay Carney said: "Any suggestion that the US is colluding with the Taliban is categorically false. Secretary Hagel addressed the questions with president Karzai in their meeting.

"The US has spent enormous blood and treasure for the past 12 years supporting the Afghan people in an effort to ensure stability and security in that country. The last thing we would do is support any kind of violence, particularly involving innocent civilians."

Carney was measured in his response, resisting a call at the press conference to use more strident language. In the past, the Obama administration responded more vigorously to critical comments by Karzai but concluded this was counter-productive.

Carney suggested the latest comments would not have an impact on the schedule for withdrawal, which he stressed had been put in place with agreement with Nato and other allies.

"There is no question there have been a number of difficult security incidents, and there have been comments by President Karzai with which we have disagreed. But our policy has not changed. We went into Afghanistan because we are attacked from Afghanistan."

A decison on the size of the post-2014 US force would be made at a later date by Obama., Carney added.

The latest insider attack capped a troubled three-day visit by Hagel. The faltering start will provide more material for his many critics in Congress who opposed his nomination, particularly after his hesitant appearance at his Senate confirmation hearing.

A press statement from Isaf military headquarters in Afghanistan said the two Americans were killed in an apparent 'green-on-blue' incident, along with at least two Afghan soldiers. A further 10 were wounded. The attacker used a machine-gun mounted on a truck in the village of Jalrez.

Hagel failed to resolve the dispute in Wardak province over withdrawal of special operations forces. He was also scheduled to hand over control of Parwan prison to Afghan authorities but this was cancelled a day before the ceremony.

It is understood the deal collapsed amid continued disagreement over detention of prisoners without trial, and a US demand that it have power to block the release of inmates it considers particularly dangerous.