The attack at the Herat consulate began at around 6am yesterday when a truck carrying armed fighters pulled up at the front gate, the US State Department said.
Gunmen attacked the Afghan police and security guards manning the front gate and soon afterwards two car bombs exploded, causing serious damage.
Afghan security forces and US commandos fought off the attackers while American diplomats took shelter. Seven militants were reported killed in the fighting.
Stung by criticism that it had misrepresented the details of the Benghazi attack last year, the State Department rushed out a late-night statement confirming that no Americans had been injured.
James Cunningham, the US ambassador to Kabul, condemned "this senseless loss of life".
"We are reminded again of the very real human toll exacted by terrorism. The perpetrators of this attack have shed Afghan blood on Afghan soil," he said.