SANAA, Yemen - An American photojournalist and a South African teacher were killed Saturday during a high-risk, U.S.-led raid to free them from al-Qaeda-affiliated militants in Yemen, an Arab country that is a centerpiece of U.S. counterterrorism efforts in the region.

The predawn raid was the second rescue attempt in as many weeks to free Luke Somers, 33, a freelance photographer and editor kidnapped just over a year ago in Yemen's capital.

South African Pierre Korkie, abducted 18 months ago with his wife in the city of Tazi, also was killed by militants as U.S. forces descended upon the militants' compound in southern Yemen. A South African aid group trying to negotiate Korkie's release said he was a day from freedom after a deal late last month that included a "facilitation fee" to the kidnappers. The relief organization had told Korkie's wife that "the wait is almost over."

President Obama said he ordered the raid because Somers was believed to be in "imminent danger." The president, in a statement, condemned Somers' killing as a "barbaric murder," but did not mention Korkie, 56, by name, offering condolences to the family of "a non-U.S. citizen hostage." The South African government said it was informed that Korkie died during the mission by American special forces.

"It is my highest responsibility to do everything possible to protect American citizens," Obama said. "As this and previous hostage rescue operations demonstrate, the United States will spare no effort to use all of its military, intelligence and diplomatic capabilities to bring Americans home safely, wherever they are located."

About 40 American special operations forces were involved in the rescue attempt, which followed U.S. drone strikes in the area, U.S. officials said. The rescuers, backed by Yemeni ground forces, advanced within 100 meters of the compound in Shabwa province when they were spotted by the militants. A firefight ensued.

Amid the fighting, U.S. forces saw a militant briefly enter a building on the compound. U.S. officials believe it was then that Somers and Korkie were shot. When Americans entered the building, they found both men alive, but gravely wounded.

Officials said that based on the location where Somers and Korkie were being held, there was no possibility that they were struck by American gunfire.

U.S. forces pulled Somers and Korkie onto V-22 Ospreys, and medical teams began performing surgery in midair. One hostage died during the short flight; the second died after the Ospreys landed on the USS Makin Island, a Navy ship in the region.

The raid was over in about 30 minutes.

U.S. officials disclosed details of the mission on the condition of anonymity because they were not authorized to publicly discuss the raid.

Saturday's operation was the second rescue attempt by U.S. and Yemeni forces to bring Somers home alive. On Nov. 25, American special operations forces and Yemeni soldiers raided a remote al-Qaeda safe haven in a desert region near the Saudi border.

Eight captives, including Yemenis, a Saudi, and an Ethiopian, were freed. Somers was not at that location. He and five other hostages had been moved days earlier, officials later said.

Roughly a dozen people are believed held by al-Qaeda militants in Yemen.

On Thursday, al-Qaeda militants released a video showing Somers and threatening to kill him in three days if the United States did not meet the group's unspecified demands or if another rescue was attempted.

U.S. officials said that threat prompted Obama to move quickly. Using information obtained during the first raid, U.S. officials believed Somers was being held Shabwa province, a stronghold of al-Qaeda in the Arabian Peninsula, the terrorist group's Yemeni branch. Officials believed a second hostage was there, too, but did not know it was Korkie.

By Thursday evening, the Pentagon had sent the White House a proposed plan, which Obama approved the following day. Officials alerted Yemen's President Abd Rabbuh Mansur Hadi, who gave his support.

Hadi has been a critical U.S. partner in seeking to undermine Yemen's dangerous al-Qaeda affiliate. With the permission of Yemen's government, the U.S. has for years launched drone strikes against militant targets in the country and provided Yemen with hundreds of millions of dollars in security assistance.

When Obama announced U.S. airstrikes this year against militant targets in Syria and Iraq, he held up the Yemen effort as a comparable model.

Yemen's highest security body, the Supreme Security Committee, issued a rare statement Saturday acknowledging that the country's forces had carried out the raid with "American friends." The committee said all the militants holding the hostages were killed in the operation.

No American forces were killed or sustained serious injuries in the raid. Yemen's government said four of its forces were wounded.

Korkie was abducted in May 2013 along with his wife, Yolande, who was doing relief work. She was released in January without ransom as a result of negotiations by the South African relief group, Gift of the Givers.

But al-Qaeda militants demanded a $3 million ransom for Korkie's release, according to those close to the negotiations. Although that demand was dropped, the kidnappers did insist on the "facilitation fee," according to the aid group. The undisclosed amount was raised by Korkie's family and friends, according to the South African Press Agency.

The U.S. government has a policy against paying ransoms to win the release of hostages.