A rocket fired on to a Nato airbase damaged the aircraft of America’s top military officer and wounded two ground crew, officers said.

Two insurgent rockets hit Bagram airfield overnight and one caused shrapnel damage to the door of a C-17 aircraft being used by Gen Martin Dempsey, chairman of the United States Joint Chiefs of Staff.

Gen Dempsey and his staff were asleep in their quarters at the time of the incident, and American officers said they were at no risk. Two American maintenance crew were slightly wounded.

Gen Dempsey had to use another aircraft to leave Bagram, north of Kabul, the AFP news agency reported.

Colonel Thomas Collins, a coalition spokesman, told Reuters: "He was nowhere near the aircraft. We think it was a lucky shot.”

However, the attack will be deeply embarrassing to the US military as it tries to hand responsibility for security over to Afghan forces.

Gen Dempsey had held meetings with Afghan generals to discuss the growing threat of “green on blue” killings, where Afghan security personnel have turned their guns of their Nato allies.

A Taliban spokesman claimed responsibility for the attack in a text message and denied it was indirect fire, saying it was based on "accurate information".

The incident is not the first security scare to overshadow a visit to Afghanistan by a coalition leader.

David Cameron earlier this year had to order a review at Camp Bastion, Britain’s main base in Helmand, after an Afghan worker evaded a security cordon in a stolen truck and made his way on to a runway as the US Defence Secretary was arriving.

The man then apparently set the 4x4 vehicle on fire before driving at high speed towards a party of officials waiting to greet Leon Panetta’s plane.

In 2010 Mr Cameron had to change his schedule after intelligence officers said they believed the Taliban had identified his helicopter and were going to try and shoot it down.

Barack Obama made a brief overnight visit to Kabul earlier this year to proclaim a new dawn for Afghanistan after the allies had agreed a long term strategic pact. He arrived after nightfall and left before sunrise under heavy security precautions.