At least three people have been killed after insurgents attacked a US consulate in western Afghanistan.

A powerful truck bomb was detonated outside the front gates, which was followed by a gun battle with security forces.

The attack in Herat, claimed by the Taliban, underscored a worrying security picture as Afghanistan prepares to take over from foreign combat troops after 12 years of war.

A spokesman for the US embassy in Kabul said all US personnel in the consulate in Herat were safe and had been accounted for.

He described the incident as a "complex" attack that included a car bomb.

A US State Department statement later said the attack was over.

A local police commander said a police officer and a translator had been killed and two Afghan staff working in the consulate had been wounded.

However, a spokesman for the main hospital in Herat later said three people, including two police and a security guard, had been killed and 17 wounded.

The US State Department statement said a truck carrying attackers had driven up to the front gate of the consulate and insurgents began attacking Afghan guards and other security contractors.

It said the truck later exploded.

The attack came two days after commemorations for the 11 September 2001 attacks on the US that precipitated the war in Afghanistan.

Exactly two years ago, insurgents staged an attack on the main US embassy and NATO headquarters in the heart of Kabul, killing at least nine people.