By Sharafuddin Stanekzai
HERAT, Afghanistan (Reuters) - At least three people were killed when insurgents attacked the U.S. consulate in western Afghanistan's main city on Friday, detonating a powerful truck bomb outside the front gates and launching a gunbattle with security forces, officials said.
The bold attack in Herat, claimed by the Taliban, once again underscored a worrying security picture as Afghanistan prepares to take over from foreign combat troops after 12 years of war and stage crucial presidential elections next year.
While the circumstances of the attack were initially unclear, a spokesman for the U.S. embassy in the Afghan capital of Kabul said all U.S. 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 U.S. State Department statement later said the attack was over.
Herat police chief General Rahmatullah Safi said a police officer and a translator had been killed and two Afghan staff working in the consulate had been wounded.
Abdul Raoof Ahmadi, 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.
Safi said Afghans and Americans had been trapped inside the consulate while fighting raged outside. "Taliban insurgents are in one compound fighting with Afghan guards and Americans are in another compound safe," he said.
The U.S. 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 Taliban quickly claimed responsibility for the attack in Herat.
"Our aim for this attack is to show the Americans that they are not safe anywhere in this country," Taliban spokesman Qari Yusuf Ahmadi said in a statement emailed to reporters.
Insurgents often stage so-called complex attacks involving suicide bombers and fighters on targets such as Afghan government and security forces, especially in the more volatile south and east, although assaults on high-profile and well-protected U.S. targets are less common.
The attack began at about 6 a.m. (0150 GMT). A Reuters witness said he saw flames in front of the compound rising from the wreckage of the vehicle and could hear the gunbattle as the attack unfolded.
The attack came two days after Americans staged solemn commemorations for the September 11, 2001, attacks on the United States that precipitated the war in Afghanistan.
Exactly two years ago, insurgents staged a daring attack on the main U.S. embassy and NATO headquarters in the heart of Kabul, killing at least nine people in a battle lasting several hours as attackers fired from a partially constructed building.
(Additional reporting by Dylan Welch and Mirwais Harooni in KABUL and Mark Hosenball in WASHINGTON; Writing by Paul Tait; Editing by Matt Driskill)