KABUL, Afghanistan — A veteran Afghan air force pilot opened fire Wednesday inside a NATO military base, killing eight U.S. service members and an American civilian contractor who had gathered for a morning meeting, Afghan and U.S. officials said.

The shooting was the deadliest in a string of recent killings carried out by members of the Afghan security forces against their colleagues and coalition partners. In April, there have been four attacks inside NATO or Afghan military bases by Afghan servicemen or insurgents dressed like them. And in another major security breach, nearly 500 prisoners were freed from a heavily guarded jail when Taliban insurgents tunneled into it — a mission that Afghan officials believe occurred with the cooperation of prison guards. Fourteen Americans have been killed this month by members of the Afghan military.

Taken together, the spate of fraternal violence points to a serious problem with the loyalty of members of the Afghan security forces and their vulnerability to infiltration by the Taliban. The problem appears to have no simple solution. The Afghan military has begun an assessment to identify vulnerabilities in bases, register every member in a biometric database, and develop a counterintelligence force. But such measures are time-consuming and still cannot prevent soldiers from spontaneously turning on their comrades and partners.

The attack early Wednesday turned a routine meeting on the first floor of the Air Force building — on the military side of Kabul”s airport — into a scene of bloodshed.

The American advisers had gathered there as they do daily, according to Afghan officers present, when a pilot who served for about two decades in the Afghan air force suddenly opened fire.

Another account, provided by a Defense Ministry spokesman, said the air force officer got into a heated argument during the meeting, left the room, then came back and started shooting.

From his third-floor office, an Afghan air force general heard the gunfire and saw people jumping out of windows to escape the fusillade. In addition to the Americans who were killed, an Afghan soldier died and five others were wounded. A U.S. reaction force surrounded the building and neighboring offices and prevented people from leaving while they secured the scene. Another Afghan officer on the compound identified the shooter as Ahmad Gul.

“I”m amazed. I have no idea why he would do this,” the officer said.

One Afghan air force intelligence officer at the meeting said the shooter opened fire with no warning and jumped out the window in a panic to escape, injuring his leg in the process, according to the officer”s son, Samin Haq Barwar.

The Afghan air force, with about 4,000 members, is the smallest and least developed of the Afghan security forces. It has a small fleet of cargo planes and helicopters, although Afghan defense officials have been pushing for the United States to buy the force fighter jets.

The other recent attacks carried out by Afghans in uniform have targeted the Afghan government and military, as well as foreign troops. Gunmen have penetrated the Ministry of Defense in Kabul, the Kandahar police headquarters and an Afghan army base in Laghman province. Earlier this week, the Taliban managed to free inmates from Kandahar”s largest prison by digging a tunnel into it from a house more than 1,000 feet away.

U.S. military officials say they have been expecting the Taliban to increase its efforts to infiltrate Afghan security forces — either to steal information or plan attacks. Officials generally classify such efforts in one of three ways: “pure” infiltration, when a recruit joins the security forces in order to carry out Taliban missions; “mimicry,” when an insurgent wears a security forces uniform as a disguise to gain access to bases; and “co-option,” when insurgents persuade a member of the security forces to help carry out a mission.

The gunman who opened fire in the Defense Ministry headquarters earlier this month was not a soldier but is believed to have been wearing an Afghan army uniform, while the suicide bomber who killed Kandahar”s provincial police chief was actually a member of the police force.

The suicide bombing at the army base in Laghman province, which killed five American soldiers and four Afghan soldiers, was carried out by an Afghan soldier who had been on the force for 14 months, said a Western intelligence official.

In an earlier attack, an Afghan sergeant major admitted to orchestrating a suicide bombing after being promised by Badruddin Haqqani, a high-level insurgent in Pakistan, that a debt would be forgiven and he would receive $25,000 for his assistance.

In some cases, violence directed against the U.S-led coalition and its Afghan allies appears to stem from personal problems rather than Taliban ties. The Afghan border police officer who killed six American soldiers in Nangarhar province in November had a fight with his father on the morning of the shooting. Later in the day, he reached a “boiling point” and opened fire, the Western intelligence official said.

“The numbers of true infiltration are relatively small, but we predict they will attempt to increase that tactic during the year,” the official said.