Taliban militants unleashed car bombs at a US Consulate in western Afghanistan on Friday morning, triggering a firefight with security forces in an attack that killed at least two Afghans.

The US said all its personnel from the mission were safe and that American forces later secured the site.

The attack in the city of Herat along with a suicide truck bombing in the country's east that wounded seven Afghans underscored the perilous security situation as US-led troops reduce their presence ahead of a full withdrawal next year. It was also a rude return to reality for Afghans who had spent a day and a half celebrating their nation's first international soccer championship.

Taliban spokesman Qari Yousef Ahmadi took responsibility for the Herat attack in a phone call with the Associated Press.

According to General Rahmatullah Safi, Herat province's chief of police, the attack began around 6 am when militants in an SUV and a van set off their explosives-laden vehicles while others on foot fired on Afghan security forces guarding the compound.

An Afghan police officer and an Afghan security guard were killed, though it was not clear whether they died in the explosions of the two vehicles or in the gunfire, Safi said. At least seven attackers were killed, including the two drivers of the explosives-laden vehicles, he said, and several people were wounded.

US State Department deputy spokeswoman Marie Harf said in a statement that the assault began around 5.30 am, when "a truck carrying attackers drove to the front gate, and attackers possibly firing rocket propelled grenades and assault rifles started firing at Afghan forces and security guards on the exterior of the gates. Shortly after, the entire truck exploded, extensively damaging the front gate."

Rafi said US special forces entered the area to secure the compound, and that no attackers managed to breach it. Harf's statement said "American security personnel" were among the response team, and added that "it appears American and contract security personnel addressed any attackers who managed to enter the compound."

Robert Hilton, a spokesman for the U.S. Embassy in Kabul, said that "all consulate personnel are safe and accounted for."

Footage broadcast on Afghanistan's Tolo television network showed Afghan police dragging away a badly bloodied man from the scene, but it was unclear if he was dead or who he was. Rubble and twisted pieces of metal lay strewn in a seemingly wide area near the consulate, the footage showed.

Herat lies near Afghanistan's border with Iran and is considered one of the better developed and safer cities in the country, with a strong Iranian influence. Most of the violence in Afghanistan has been concentrated in the east and the south.