KABUL, Afghanistan – NATO and Afghan forces have killed a former Guantanamo detainee who returned to Afghanistan to become a key al-Qaida ally, international officials said Saturday.

The militant’s death was a reminder of the risks of trying to end a controversial detention system without letting loose people who will launch attacks on Americans.

Saber Lal Melma, who was released from Guantanamo in 2007, had been organizing attacks in eastern Kunar province and funding insurgent operations, NATO said.

A NATO statement described Melma as a “key affiliate of the al-Qaida network” who was in contact with senior al-Qaida members in both Afghanistan and Pakistan.

Another former detainee who joined the al-Qaida franchise in Yemen was killed in a recent U.S. airstrike there.

Troops surrounded Melma’s house in Jalalabad city on Friday night and shot him dead when he emerged from the building holding an AK-47 assault rifle. Several other people were detained, NATO said.

A guard at the house, Mohammad Gul, said a group of American soldiers scaled the walls of the compound around 11 p.m. and stormed the house, shooting Melma in the assault. Three others were detained, Gul said.

Melma joined a long list of detainees believed to have reconnected with al-Qaida. In 2009, the Pentagon said 61, about 11 percent, of the detainees released from Guantanamo had rejoined the fight.

About 520 Guantanamo detainees have been released from custody or transferred to prisons elsewhere in the world. There are 171 inmates still held at the facility in Cuba.

After the fall of the Taliban, Melma, 49, was given the rank of brigadier general in the Afghan National Army in Kunar, according to a file made public by WikiLeaks.

But he was suspected of helping to carry out rocket attacks against U.S. troops, and he was captured in August 2002 while attending a meeting with U.S. military officials in Asadabad and transferred to Guantanamo in October of that year.