HERAT, Afghanistan (AFP) - Four insurgent gunmen launched a pre-dawn attack on India's consulate in the western Afghan city of Herat on Friday before being repelled by security forces, in an assault highlighting instability as Nato troops withdraw.
There were no casualties among Indian staff but at least two policemen were wounded when the heavily-armed attackers stormed a house close to the consulate and opened fire on the building.
Afghanistan is in the middle of elections to choose a successor to President Hamid Karzai, who has ruled since the fall of the 1996-2001 Taleban regime.
Pakistan was the Taleban's main ally and the Pakistani security forces have often been accused of assisting the insurgents, especially with attacks on Indian targets in Afghanistan.
"Four Taleban attackers entered a residential house behind the consulate in the early morning," said Mohammad Pashtoon, commander of Herat's paramilitary Quick Reaction Force.
"Security forces evacuated residents and fought to clear the building. All attackers have been killed."
The multi-storey house was left badly damaged by the operation to hunt down the gunmen, who were armed with machine guns and rocket-propelled grenades.
Delhi's foreign ministry spokesman Syed Akbaruddin told the Ndtv news channel that Indian police guarding the consulate had shot one gunman trying to breach the perimeter before Afghan forces arrived.
India has been a key supporter of Kabul's post-Taleban government, and analysts have often pointed to the threat of a "proxy war" in Afghanistan between India and its arch-rival Pakistan.
The Pakistani government issued a swift condemnation, saying it was opposed to "terrorism in all its forms and manifestations".
The Taleban did not immediately claim responsibility for the attack, which came after incoming prime minister Narendra Modi invited Pakistan premier Nawaz Sharif to his inauguration in Delhi next week.
"Anti-India elements in Pakistan may be testing the resolve of India's new government," said Sameer Patil, an analyst at Gateway House, a Mumbai-based think-tank.
Afghanistan has seen a flare-up in violence ahead of the second-round presidential election on June 14, with 16 policemen killed in a series of attacks in the space of 24 hours earlier this week.
Providing security for the election is a key test for Afghan police and soldiers, with all Nato combat troops due to pull out of the country by December after more than a decade fighting the Taleban.
Friday's assault against the consulate in Herat is the latest in a long line of attacks against Indian targets in Afghanistan.
Nine civilians, including seven children, were killed in August last year when suicide bombers targeted the Indian consulate in the eastern city of Jalalabad, detonating an explosives-packed car.
In 2008, a car bomb at the Indian embassy in Kabul killed 60 people and the embassy was again hit by a suicide strike in 2009. And in 2010, two guesthouses in Kabul used by Indians were attacked.
Sharif is still mulling whether to take up the invitation to attend Modi's swearing-in ceremony, with many hoping it would help ease tensions between the nuclear-armed neighbours.
Pakistan denies backing militants active in Afghanistan and points to its own bloody fight against Islamist extremists.
India has poured US$2 billion in reconstruction aid into Afghanistan and has been asked for further support, including military assistance in Kabul's battle to contain the Taliban insurgency.
While the government in New Delhi is wary of being sucked into the unrest, it has pledged to do all it can to help promote stability in Afghanistan.
President Karzai has particularly good relations with New Delhi and obtained a Masters degree in politics when he was a student in India.