(Recasts with protests, adds analyst comment, background)
By Matthias Williams
NEW DELHI, Feb 9 (Reuters) - India hanged a Kashmiri militant on Saturday for an attack on the country's parliament in 2001, sparking clashes in Kashmir between hundreds of protesters and police who wielded batons and fired teargas to disperse the crowds.
President Pranab Mukherjee rejected a mercy petition from Mohammad Afzal Guru and he was hanged at 8 a.m. (0230 GMT) in Tihar jail in the capital, New Delhi. Security forces anticipating unrest had imposed a curfew in parts of insurgency-torn Kashmir and ordered people off the streets.
India blamed the 2001 attack on the parliament of the world's largest democracy on militants backed by Pakistan, targeting the prime minister, interior minister and legislators in one of the country's worst ever militant attacks.
Pakistan denied any involvement and condemned the attack but tension rose sharply and brought the nuclear-armed rivals dangerously close to their fourth war. Nearly a million soldiers were mobilised on both sides of the border and fears of war only dissipated months later, in June 2002.
The hanging was ordered less than three months after India executed the lone surviving gunman of a 2008 attack in the city of Mumbai in which 166 people were killed.
Saturday's execution could help the ruling Congress party deflect opposition criticism of being soft on militancy, as it gears up for a series of state elections this year and a general election due by 2014, while grappling with an economic slowdown.
"Congress has decided to be more proactive in view of the elections, not only in terms of economic policy but also matters like the hanging of Afzal Guru," said political analyst Amulya Ganguli.
"The Congress has now deprived the BJP of a propaganda plank," he said, referring to the main opposition Bharatiya Janata Party (BJP).
Government officials dismissed suggestions that electoral politics played a role in the decision to execute Guru.
In major towns of Indian Kashmir, where security forces have battled a Muslim separatist insurgency for decades, barricades were erected and hundreds of police and paramilitary force members were deployed.
"The hanging of Afzal Guru is a declaration of war by India," said Hilal Ahmad War, leader of a separatist faction.
Authorities shut down internet services and blocked social networking sites to try to stop unrest from spreading. The chief minister of Jammu and Kashmir state, Omar Abdullah, made a televised appeal for calm.
Scuffles also broke out in New Delhi between Hindu activists and demonstrators who gathered at a city-centre protest site to condemn the hanging, a Reuters witness said.
Five militants stormed the heavily guarded parliament complex in New Delhi on Dec. 13, 2001, armed with grenades, guns and explosives, but security forces killed them before they could enter the main chamber. Ten other people, most of them security officers, were killed in the clash.
Guru, an Indian national, was convicted for helping organise arms for the attackers and a place for them to stay. He had denied any involvement in the conspiracy.
India said the Pakistan-based Jaish-e-Mohammad militant group was responsible. The group fights Indian rule in Muslim-majority Kashmir.
The hanging last year of Mohammad Ajmal Kasab, the lone surviving Pakistani militant involved in the 2008 Mumbai attacks, after a long lull in executions, prompted speculation that India would move quickly to execute Guru.
But unlike Kasab's execution, which sparked celebrations in the streets, Guru's case was seen as more divisive.
Some Kashmiri leaders warned that hanging Afzal would fuel the revolt in India's part of the Himalayan region in which tens of thousands of people have been killed since 1989.
Curfews were imposed in Srinagar, the region's summer capital in the Kashmir valley, and major towns including Baramulla, Guru's home town.
Kashmir is divided between India and Pakistan, both of which claim the region in full and rule it in part. They have fought two of their three wars over the region.
India has long accused Muslim Pakistan of arming and funding militants to fight Indian forces in Kashmir. Pakistan says it only provides moral support to the fellow-Muslim people of Kashmir, who Pakistan says, face heavy-handed Indian rule.
The dispute, a legacy of the division of the sub-continent at the end of British rule, is the main factor souring relations between the neighbours. (Additional reporting by Fayaz Bukhari, Mansi Thapliyal, Ashok Pahalwan, Arnika Thakur and Satarupa Bhattacharjya; Editing by Ross Colvin and Robert Birsel)