An American major-general was shot to death Tuesday in one of the bloodiest insider attacks of the long Afghanistan war when a gunman dressed as an Afghan soldier turned on allied troops, wounding about 15 including a German general and two Afghan generals.

The American officer was Maj.-Gen. Harold Greene, a U.S. official said. An engineer by training, Greene was on his first deployment to a war zone and was involved in preparing Afghan forces for the time when U.S.-coalition troops leave at the end of this year. He was the deputy commanding general, Combined Security Transition Command-Afghanistan.

Greene was the highest-ranked American officer killed in combat in the nation's post-9/11 wars in Iraq and Afghanistan and the highest-ranked officer killed in combat since 1970 in the Vietnam War.

U.S. Army Maj.-Gen. Harold J. Greene is pictured in this August 25, 2005 handout photograph. Greene was killed and more than a dozen people were wounded, including a German general, in the latest insider attack by a man believed to be an Afghan soldier. (U.S. Army/Reuters)

Five major-generals were killed in Vietnam, the last being Maj.-Gen. John Albert Dillard, whose helicopter was shot down.

The attack at Marshal Fahim National Defence University underscored the tensions that persist as the U.S. combat role winds down in Afghanistan — and it wasn't the only assault by an Afghan ally on coalition forces on Tuesday. In eastern Paktia province, an Afghan police guard exchanged fire with NATO troops near the governor's office, provincial police said. The guard was killed in the gunfight.

It wasn't clear if the two incidents were linked, and police said they were investigating.

German, 2 Afghans also wounded

Early indications suggested the Afghan gunman who killed the American general was inside a building and fired indiscriminately from a window at the people gathered outside, the U.S. official said. There was no indication that Greene was specifically targeted, said the official who identified Greene. The official was not authorized to speak publicly by name about the incident and provided the information only on condition of anonymity.

The wounded included a German brigadier-general and two Afghan generals, officials said. A U.S. official said that of the estimated 15 wounded, about half were Americans, several of them in serious condition.

U.S. officials still asserted confidence in their partnership with the Afghan military, which appears to be holding its own against the Taliban but will soon be operating independently once most U.S.-led coalition forces leave at the end of the year.

The Iraq and Afghanistan wars have taken more than 6,700 U.S. lives.

Insider attacks rose sharply in 2012, with more than 60 coalition troops — mostly Americans — killed in 40-plus attacks that threatened to shatter all trust between Afghan and allied forces. U.S. commanders imposed a series of precautionary tactics, and the number of such attacks declined sharply last year.

The White House said U.S. President Barack Obama was briefed on the shooting. Obama and Defence Secretary Chuck Hagel both spoke with Gen. Joseph Dunford, the top U.S. general in Kabul, who said a joint U.S.-Afghan investigation was underway and who assured his bosses he still had confidence in the Afghan military.

A few U.S. generals in Afghanistan

The Pentagon's press secretary, Navy Rear Adm. John Kirby, announced that the U.S. general officer was killed in the attack but he refused to be specific about his rank, citing concern that his family had not yet been fully and officially notified. Another U.S. official said the officer was a major general. There are only a few U.S. generals in Afghanistan.

Kirby said the general and other officials were on a routine visit to the military university on a base west of Kabul.

Gen. Mohammad Zahir Azimi, a spokesman for Afghanistan's Defense Ministry, said a "terrorist in an army uniform" opened fire on both local and international troops. Azimi and U.S. officials said the shooter was killed.

Taliban spokesman Zabihullah Mujahid praised in a statement the "Afghan soldier" who carried out the attack. He did not claim the Taliban carried out the attack, although in the past the Taliban have encouraged such actions.

Such assaults are sometimes claimed by the Taliban insurgency as proof of their infiltration. Others are attributed to personal disputes or resentment by Afghans who have soured on the continued international presence in their country more than a dozen years after the fall of the Taliban from power.

Mark Jacobson, a former NATO deputy civilian representative to Afghanistan and now a senior adviser at the private Truman National Security Project, said the threat of Afghan troops turning their guns on their American partners is a serious problem.

"Any sort of insider attack, no matter who the victim is, is going to have an impact on the morale of soldiers," Jacobson said, adding that when a higher-ranking officer is killed, "you might see a wider impact on morale."