It was a risky but successful operation: Before dawn Saturday, British and other NATO forces stormed a cave tucked in the mountains and rescued two foreign female aid workers and their two Afghan colleagues being held hostage by Taliban-linked militants.

Helicopters flying under the cover of darkness ferried the rescue team to extreme northeastern Afghanistan, where they suspected the hostages were being held. After confirming that the workers were there, they raided the site, killed several militants and freed the hostages, ending their nearly two-week ordeal.

Helen Johnston, 28, of Britain and Moragwa Oirere, 26, of Kenya and their two Afghan colleagues were kidnapped May 22 while traveling on horseback in Badakhshan province. The four work for Medair, a humanitarian nongovernmental organization based in Switzerland.

“They were kidnapped by an armed terrorist group with ties to the Taliban,” said Lt. Col. Jimmie Cummings, a spokesman for the U.S.-led military coalition fighting in Afghanistan. “The kidnappers were armed with heavy machine guns, rocket-propelled grenades and AK-47s.”

Past rescue attempts in Afghanistan have not always gone so well.

In 2009, Sultan Munadi, an Afghan interpreter kidnapped alongside New York Times reporter Stephen Farrell, was killed in a hail of bullets during a rescue attempt by British commandos. In 2010, the U.S. Navy’s SEAL Team 6 tried to rescue Linda Norgrove, a Scottish aid worker, from her Taliban captors in Afghanistan. She was killed by a grenade thrown in haste by one of the American commandos.

Afghan officials said seven militants were killed during Saturday’s rescue operation, which was launched about 1 a.m.

British Prime Minister David Cameron approved the rescue operation Friday afternoon after becoming increasingly concerned about the hostages’ safety. The mission was carried out by British troops in cooperation with other NATO and Afghan forces, Cameron told reporters in London.

“It was an extraordinarily brave, breathtaking even, operation,” he said.

Separately, a NATO service member died Saturday after an insurgent attack in southern Afghanistan, the coalition said. This year, 177 foreign troops have been killed in Afghanistan.

Also in the south, Abdul Salaam, the Taliban’s military leader for three districts in southern Helmand province, was killed Friday in a joint operation by the Afghan and coalition forces in Kajaki district, the provincial governor’s office said Saturday.

In the east, NATO and Afghan forces detained a militant commander who allegedly planned and coordinated an attack Friday on a coalition base in eastern Khost province.

— Associated Press