Updated

Militants firing rockets and automatic rifles attacked the Afghan president at a ceremony in Kabul on Sunday, missing their target but killing three and wounding eight others.

The Taliban claimed responsibility for the assault that sent President Hamid Karzai and foreign ambassadors scurrying for cover, underscoring the fragile grip of his U.S.-backed government.

Gunmen opened fire as a 21-gun salute echoed over the capital at an anniversary ceremony to mark the mujahedeen victory over the Soviet occupation of Afghanistan.

Hundreds of people, including army and police that had formed an honor guard inspected by Karzai minutes earlier, fled in chaos as shots rang out. The president was hustled away, surrounded by bodyguards, and left in a convoy of four black SUVs.

The gunfire apparently came from a three-story guesthouse, popular with migrant laborers, about 300 yards from the stands where Karzai was seated alongside Cabinet ministers and senior diplomats, who all escaped unharmed. A U.S. Embassy official confirmed U.S. Ambassador William Wood was also not hurt.

A lawmaker who was about 30 yards from the president was killed in the attack.

Residents reported that a 30-minute gunbattle broke out between security forces and gunmen holed up in the guesthouse, located in a neighborhood of ruined mud brick buildings.

Defense Minister Gen. Abdul Rahim Wardak said three attackers were killed by security forces, and assault rifles and machine guns were confiscated.

Taliban spokesman Zabiullah Mujaheed said six militants were deployed to target the president, and three of those militants died in the attack. He said they were armed with guns, rockets and suicide vests although no suicide bombings were reported.

The initial moments of the attack, which came as a marching band played the finale of the national anthem, were broadcast live until TV transmissions were cut. Hundreds of dignitaries could be seen diving for cover. Two lawmakers were hit by the gunfire. One of the men slumped back in his seat, while the other lay on the ground.

Less than two hours later, Karzai appeared on state-run TV and said "everything is OK."

Appearing calm, Karzai said "the enemy of Afghanistan" tried to disrupt the ceremony but was thwarted by security forces. He said several suspects were arrested and smiled as he signed off his brief recorded statement.

About 100 people were rounded up for questioning, an Afghan intelligence official said on condition of anonymity because he was not authorized to speak to media.

Associated Press reporters saw a half dozen people, who appeared to be migrant laborers from northern Afghanistan, sitting in the back of a police van outside the guesthouse, which was pocked with bullet holes. Windows were smashed, and police barred the reporters from entering.

The militant attack, the first in the capital since mid-March, came despite unprecedented tight security for Sunday's celebrations. In January, three Taliban suicide attackers hit Kabul's upscale Serena Hotel, killing eight people, including an American.

For days Kabul was ringed by checkpoints with security forces and plainclothes intelligence officials searching vehicles. The area where the ceremonies took place had been blocked by troops, tanks and armored personnel carriers, and was closed to the general public.

The live coverage of the assassination attempt will add to the sense of insecurity in the Afghan capital, which has been spared the worst of the violence as fighting has escalated between Taliban insurgents and NATO and U.S.-led forces.

The fighting left about 8,000 dead last year, mostly militants in the south and east of the country, where Karzai's government has only a tenuous grip and little public support.

NATO Secretary General Jaap de Hoop Scheffer joined several foreign leaders, including some from neighboring Pakistan, in condemning Sunday's attack.

"The Taliban has demonstrated once again that they will use the most extreme violence to oppose Afghanistan's freedom and democratic development," de Hoop Scheffer said in a statement.

The presidency said Nasir Ahmad Latefi, a local Shiite leader, and a 10-year boy died in the attack. Lawmaker Fazel Rahman Samkanai died of his injuries at a hospital, Defense Ministry spokesman Gen. Mohammad Zahir Azimi said.

Taliban spokesman Mujaheed said the insurgents had managed to penetrate the security cordon and reach the national stadium near the parade area where the event was held.

He said BM-12 missiles — a crude rocket launched from a small platform — were used in the attack. He spoke to an AP reporter by phone from an undisclosed location.

Mohammad Saleh Saljoqi, a lawmaker at the ceremony, said there was continuous AK-47 fire, and one rocket, which he described as a rocket-propelled grenade, hit inside the Eid Gah mosque opposite where Karzai was sitting. Another rocket struck after the president had already left, about 50 yards away.

Karzai, who has led Afghanistan since soon after a U.S.-led invasion ousted the Taliban regime in 2001, has escaped several assassination attempts.

His narrowest escape since he became president came in September 2002 when a gunman opened fire at close quarters as he visited the southern city of Kandahar. Three people, including the gunman, died in that attack.