(Adds quotes, details, 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, and security forces, anticipating protests in response to the execution, imposed a curfew in parts of Kashmir and ordered people off the streets.
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, officials said.
India blamed the 2001 attack on the parliament of the world's largest democracy on militants backed by Pakistan.
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.
"This is only about the law taking its course," Home Secretary R.K. Singh told reporters after the execution.
Barricades were erected and hundreds of police and paramilitary forces were deployed in major towns of Indian Kashmir, which has battled a separatist insurgency for decades.
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.
The assault on India's seat of power was one of the worst militant attacks in the country's post-independence history.
Guru, an Indian national, was convicted for helping organise arms for the attackers and a place for them to stay. Guru 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 militant of 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 Muslim separatist revolt against Indian rule in the Himalayan region that has killed tens of thousands of people since 1989.
Government officials dismissed suggestions that electoral politics played a role in the decision to execute Guru. The Congress party-led coalition, which the opposition has accused of being soft on terrorism, faces a tough re-election fight in 2014.
The curfew has been 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 Pakistan of arming and funding militant groups to attack 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, Ashok Pahalwan, Arnika Thakur and Satarupa Bhattacharjya, editing by Ross Colvin)