The gunbattle between the assailants and security forces ended after about seven hours, with the death of the two rebel gunmen. Most of the casualties were the victims of the car bomb, including the driver.
One of the Islamic rebel groups fighting for the independence of India's Jammu-Kashmir state claimed responsibility for the attack.
Police said the assault would have been much worse if the assailants had realized that the lawmakers have been meeting in a nearby building since the state legislature had been damaged in an accidental fire.
Seven of the 100 or so lower-ranking employees still working in the legislature, including secretaries and clerks, were among those killed during the gunbattle, police said. Three militants and nine security force soldiers were also slain, police said.
The death toll in the attack was the highest in Jammu-Kashmir since 1999, when 35 Hindus were massacred by militants while on a pilgrimage toward a cave they regard holy in the mountains in the state.
For 12 years, more than a dozen Muslim militant groups have been fighting for the independence of Jammu-Kashmir, the only state in mostly Hindu India with a Muslim majority. Tens of thousands of people have died.
On Monday, the rebels brought the hijacked vehicle to the assembly building and blew it up at around 2 p.m. local time in Srinagar, the summer capital.
Although the driver was killed, the two other gunmen dressed in police uniforms left the vehicle before the blast and rushed into the legislature.
Firing their guns and throwing hand grenades, they engaged in a battle with security forces, said R.K. Jala, the superintendent of police.
The Pakistan-based militant group Jaish-e-Mohammed claimed responsibility for the attack in a telephone call to The Associated Press in Srinagar, the summer capital of Jammu-Kashmir state.
The group was launched by a Pakistani radical leader, Massood Azhar - one of three men freed from Indian jails in 1999 in exchange for a hijacked Indian plane and its passengers that were flown to Afghanistan.
Monday's attack was the worst in the state since the terrorist attacks in New York and Washington on Sept. 11, which have been blamed on Saudi exile Osama bin Laden, who is based in Afghanistan. Its Taliban government supports the rebels fighting in Kashmir.
"At a time when the democratic world has formed a broad and determined coalition against international terrorism, India cannot accept such manifestations of hate and terror from across its borders," the External Affairs Ministry said in a statement. It said the international community expects Pakistan to take action against Jaish-e-Mohammad.
The Pakistan government condemned the car bombing ad India, saying, "This act of terrorism ... appears to be aimed at maligning the legitimate struggle of the Kashmiri people for their right to self-determination."
Some Indian officials had expected that pro-Taliban militants fighting in Kashmir would return to Afghanistan to help defend it from a likely U.S. military attack to kill or capture bin Laden. But police reported over the weekend that few of the rebels were moving and that attacks by them on Indian military forces had actually declined since Sept. 11.
The car bomb, which shattered the glass windows of a nearby hotel and more than two dozen shops, left a dozen dead bodies lying in the streets outside the legislature. Police said at least 31 people were killed and 75 wounded.
Most of the victims waiting on sidewalks and in cars as police stopped traffic while the legislators left the auxiliary building, police said.
The attackers hijacked a federal telecommunications department vehicle and released its driver shortly before the attack, police said. But the claim of responsibility said they rented a cab and loaded it with explosives.
The militant groups don't recognize the legitimacy of the legislature, which was created by the Indian government. Many Kashmiris boycott the elections that choose local people as the lawmakers.
Pakistan openly supports the militants fighting in Jammu-Kashmir. India has accused Pakistan of arming and training them, too.
By Qaiser Mirza © MMI The Associated Press. All Rights Reserved. This material may not be published, broadcast, rewritten, or redistributed