KABUL, Afghanistan — In what appeared to be a concerted effort to test the capabilities of Afghan security forces in the capital, Taliban insurgents sought to penetrate the heavily fortified heart of Kabul on Friday, blasting their way into a residential compound of the International Organization for Migration, an agency that has worked with the United Nations.

The Afghan forces managed to hold the attackers at bay, and hundreds of international agency employees in nearby compounds escaped harm. But at least four people were killed, including a six-year-old girl, and 13 others were wounded, including an Italian woman. And it took more than six hours for hundreds of Afghan police officers to subdue no more than six attackers with suicide vests, guns and grenade launchers.

Explosions continued through the night. The authorities said they were from booby traps the attackers had planted in the compound.

It was the first example of what the military calls a “complex attack,” involving both gunmen and suicide bombers, in the capital since insurgents attacked the headquarters of the unarmed traffic police force in January. It took Afghan forces nine hours to bring that to an end.

There have been other serious attacks in Kabul more recently, including a deadly one just a week earlier in which a suicide car bomber killed six American military advisers, but those have been single bombings, rather than extended engagements.

A coalition official said the Afghan police’s Quick Reaction Force, along with other units, responded quickly and competently on Friday. “This is a high-end Afghan unit that is down there,” he said. “I’d put it against most Western SWAT teams that are out there.”

American officials have in the past expressed concern about the timidity of Afghan security forces in Kabul when faced with determined attacks from bands of insurgents, and advisers embedded with their forces have sometimes had difficulty encouraging them to move aggressively to contain attackers. That has been a focus of training.

In April 2012, for instance, a complex attack on Parliament in Kabul went on for 18 hours before it was subdued. And the previous September, the authorities were embarrassed when it took 19 hours to clear insurgents from a building under construction, which the insurgents used to fire on the American Embassy and nearby NATO headquarters.

An error has occurred. Please try again later.

You are already subscribed to this email.

“How could a fight prolong for so many hours, even though we have hundreds and hundreds of Afghan forces deployed?” asked Amrullah Aman, a retired Afghan general and a military analyst. “It means Afghan forces need better equipment, better training.” He also questioned how the attackers got so much ammunition, weaponry and explosives into the city center, which is a lattice of police checkpoints.

The compound that the insurgents attacked is close to the main facility of the United Nations in Kabul, as well as guesthouses and offices used by foreigners, a post of the Afghan Public Protection Force and a hospital for the national intelligence service. The Taliban themselves claimed that the building they invaded was a Central Intelligence Agency training center, according to the insurgents’ spokesman, Zabiullah Mujahid, who was reached by telephone. Police officials denied that was the case.

The dead included an Afghan policeman and a Nepalese Gurkha guard, who apparently had been on the gate at the migration agency’s compound, said Gen. Mohammad Ayoub Salangi, Kabul’s police chief. All “five or six” of the attackers were killed, he said.

The attack began when one of the insurgents detonated his suicide vest to clear a path for the others to force their way into the compound. The initial blast could be heard miles away. Among the 13 wounded were three agency employees and one person working for the International Labor Organization.

Jan Kubis, the top United Nations official here, expressed gratitude for the “quick actions” of the Gurkha guards as well as the Afghan police.

A Western diplomat, speaking on condition of anonymity in line with his country’s policy, said: “From the Afghan point of view, it could have been a lot better. From the Taliban point of view, it should have been a lot worse.”

Early Saturday morning, as the police were still sifting through the wreckage of the precious day’s attack and updating the number of dead, another suicide bomber wearing a burqa blew himself up inside the city. Details about the number of injured or dead were not immediately available.

Correction: June 5, 2013

An article on Thursday about an attack by suicide bombers on an International Committee of the Red Cross compound in Jalalabad, Afghanistan, described incorrectly another aid organization, the International Center for Migration, whose office in Kabul, the Afghan capital, was attacked recently. The center is an independent agency that has worked with the United Nations. It is not a United Nations agency; nor is it a United Nations-affiliated agency, as it was described imprecisely in an article on May 25 about the Kabul attack.

A version of this article appears in print on May 25, 2013, on Page A9 of the New York edition with the headline: Taliban Attack U.N. Affiliate’s Compound in Kabul, Testing Afghan Security Forces. Order Reprints|Today's Paper|Subscribe