Heavily-armed gunmen launched a pre-dawn attack on the Indian consulate in the Afghan city of Herat.
At least three attackers stormed nearby houses to fire on the compound with machine guns and rocket-propelled grenades, police said.
The gunmen were killed in a firefight with security forces that lasted several hours, officials added.
Afghanistan has seen a surge in attacks in recent weeks as foreign troops begin to withdraw from the country.
Questions will now be asked as to how insurgents were able to get into one of the most secure parts of Herat, the BBC's Bilal Sarwary reports from Kabul.
He says this is the latest in a long line of attacks on Indian targets in Afghanistan.
It is not clear who carried out this attack, but previous incidents have been blamed on militants from the Haqqani network, an al Qaeda-linked group suspected of having ties to Pakistani military intelligence.
The latest attack comes on the eve of the inauguration of new Indian Prime Minister Narendra Modi, which will be attended by Afghan President Hamid Karzai.
Mr Modi condemned the attack and said he was "closely monitoring the situation".
The attackers are reported to have entered homes around the consulate at around 03:00 local time (22:30 GMT Thursday), and began shooting on the compound.
Some reports suggested there were up to four gunmen.
A team of commandos from the Indo-Tibetan Border Police at the consulate initially held off the assault, until they were joined by Afghan forces.
"There were three suicide bombers armed with AK-47s, RPGs, hand grenades and suicide vests," Herat police chief General Samihullah Qatra told Reuters news agency.
"Our security forces killed all of them. Only five of our security forces were wounded."
Herat lies near Afghanistan's border with Iran and is considered one of the safer cities in the country.
In September 2013, the Taliban launched a similar assault on the US consulate in the city, killing at least four Afghans but failing to enter the compound or hurt any Americans.
Millions of Afghans defied Taliban threats to take part in the first round of elections in April to replace outgoing President Karzai.
The second round, due in mid-June, pits front-runner Abdullah Abdullah against Ashraf Ghani, a former World Bank economist.