The attack that killed Ambassador Chris Stevens -- the first U.S. diplomat to die in the line of duty since 1979 -- came on Tuesday's 11th anniversary of the Sept. 11 terrorist strike and presented a new foreign policy crisis for the United States in a region trying to recover from months of upheaval.
Libya's interim president, Mohammed el-Megarif, apologized for what he called the "cowardly" assault on the consulate, which also killed several Libyan security guards in the eastern city. Just before the Benghazi violence, protests also flared in Egypt, where crowds angry over the film climbed the walls of the U.S. Embassy in Cairo and tore down an American flag, which they replaced briefly with a black, Islamist flag.
The protests were touched off by an obscure movie made in the United States by a filmmaker who calls Islam a "cancer." Video excerpts posted on YouTube depict the Prophet Muhammad as a fraud, a womanizer and a madman in an overtly ridiculing way, showing him having sex and calling for massacres.
But the brazenness of the embassy assaults -- the first on U.S. diplomatic facilities in Libya and Egypt -- were signs of the lawlessness that has taken hold in the two countries after revolutions ousted their autocratic secular regimes and upended the tightly controlled police state. Islamists have emerged as powerful forces, and security forces have largely broken down.
In Libya, the volatility is further compounded by the wide availability of heavy weapons and the numerous armed militia factions that remain more powerful than security forces.
Stevens, 52, died as he and a group of embassy employees went to the consulate to try to evacuate staff when the mob of protesters, including gunmen armed with machine guns and rocket-propelled grenade, attacked.
The crowd, which numbered several thousand strong, moved on the consulate Tuesday evening, firing in the air outside the compound. The consulate is a one-story villa located in a fenced garden in downtown Benghazi. A small contingent of Libyan security forces protecting the facility also fired in the air, trying to intimidate them, said Wanis el-Sharef, the deputy interior minister of Libya's eastern region.
But faced with the mob's superior size and firepower, the Libyan security withdrew, el-Sharef said. Gunmen stormed the building, looted its contents and torch it, he said.
By the end of the assault, much of the building was burned out and trashed. On Wednesday, Libyans wandered freely around the burned-out building, taking photos of rooms where furniture was covered in soot and overturned. Walls were scrawled with graffiti.
Details of how the Americans were killed were still being pieced together Wednesday. But according to al-Sharef's account, two distinct attacks took place.
Al-Sharef said Stevens and a consulate staffer who had stayed behind in the building were killed in the initial attack on the consulate.
The rest of the staff successfully evacuated to another building nearby, preparing to move to Benghazi Airport after daybreak to fly to the capital, Tripoli, he said.
Hours after the storming of the consulate, a separate group of gunmen attacked the other building, opening fire on the more than 30 Americans and Libyans inside. Two more Americans were killed and 32 wounded -- 14 Americans and 18 Libyans, he said.
There was no immediate confirmation of al-Sharef's account.
Dr. Ziad Abu Zeid, who treated Stevens, told The Associated Press that he died of asphyxiation, apparently from smoke. In a sign of the chaos during the attack, Stevens was brought by Libyans to the Benghazi Medical Center with no other Americans, and no one at the facility knew who he was, Abu Zeid said.
Stevens was practically dead when he arrived before 1 a.m. Wednesday, and "we tried to revive him for an hour and a half, but with no success," Abu Zeid said. The ambassador was bleeding in his stomach because of the asphyxiation but had no other injuries, he said.
The State Department identified one of the other Americans killed as Sean Smith, a foreign service information management officer. The identities of the others were being withheld pending notification of next of kin.
"I strongly condemn the outrageous attack on our diplomatic facility in Benghazi," Obama said in Washington, adding the four Americans "exemplified America's commitment to freedom, justice, and partnership with nations and people around the globe."
Obama ordered increased security to protect American diplomatic personnel around world.
"Make no mistake we will work with the Libyan government to bring to justice the killers who attacked our people," he said.
Obama added: "We reject all efforts to denigrate the religious beliefs of others, but there is absolutely no justification for this type of senseless violence, none."
Stevens was a career diplomat who spoke Arabic and French and had already served two tours in Libya, including running the office in Benghazi during the revolt against Gadhafi. He was confirmed as ambassador to Libya by the Senate earlier this year.
Before Tuesday, five U.S. ambassadors had been killed in the line of duty, the last being Adolph Dubs in Afghanistan in 1979, according to the State Department.
El-Megarif offered his condolences to the U.S. and also vowed to bring the culprits to justice and maintain close relations with Washington.
"We extend our apology to America, the American people and the whole world," el-Megarif said.
In Benghazi, the bloodshed stunned many Libyans, especially since Stevens was popular among many factions and politicians, including Islamists, and seen as a supporter of their uprising last year against longtime dictator Moammar Gahdafi.
The leader of Ansar al-Shariah, an armed ultraconservative Islamist group, denied any involvement in the attack.
"We never approve of killing civilians, especially those who helped us (like Ambassador Stevens)," said Youssef Jihani. "We are well-educated and religious."
The violence raised worries that further protests could break out around the Muslim world as knowledge of the anti-Islam movie spread.
So far, the reaction was limited.
About 50 protesters burned American flags outside the U.S. Embassy in Tunisia's capital Wednesday but were kept away from the building by reinforced security. And in Gaza City, dozens of protesters carrying swords, axes and black flags chanted "Shame on everyone who insults the prophet." The rally was organized by supporters of a militant group aligned with the ruling Hamas movement.
In Cairo, some 200 Islamists staged a second day of protest outside the U.S. Embassy on Wednesday, but there was no repeat of the previous day's scaling the embassy walls.
"Obama we are all Osama," chanted some of the bearded ultraconservatives, alluding to the al-Qaida leader Osama bin Laden.
Mahmoud Mohammed, a 25-year-old factory worker, demanded a U.S. apology for the offending film and the prosecution of those behind it. "They violated the honor of the prophet and his wives, and made him out to be sex crazed. This is nonsense," he said.
The uproar over the film also poses a new test for Egypt's new Islamist president, Mohammed Morsi, who has yet to personally condemn the riot outside the U.S. Embassy in Cairo or say anything about the offending film. Many of the protesters demanded he speak out against the movie.
His spokesman, Yasser Ali, condemned the film. While the government is responsible for the security of foreign diplomatic missions, he said, it guarantees the right of peaceful protests.
"However, the state will deal firmly with any irresponsible attempts to break the law," he said.
Egypt's top prosecutor, meanwhile, has placed the names of 10 Christian Egyptians living abroad on the list of arrest-on-arrival at the nation's airports. The 10 include two clerics and a well-known, U.S.-based Christian activist who is promoting the offending film.
If arrested, the 10 would be questioned on allegations of showing contempt to religion and could possibly be charged and tried.
Afghanistan's government sought to avert an outbreak of protests. President Hamid Karzai condemned the movie, which he describes as "inhuman and insulting." Authorities also temporarily shut down access to YouTube, the video-sharing site where excerpts of the movie were posted, said Aimal Marjan, general director of Information Technology at the Ministry of Communications.
The two-hour movie that sparked the protests, titled "Innocence of Muslims," came to attention in Egypt after its trailer was dubbed into Arabic and posted on YouTube.
A man identifying himself as Sam Bacile, a 56-year-old California real estate developer, said he wrote, produced and directed the movie.
He told the AP he was an Israeli Jew and an American citizen. But Israeli officials said they had not heard of Bacile and there was no record of him being a citizen. They spoke on condition of anonymity because they are not permitted to share personal information with the media.
Separately, the film was being promoted by an extreme anti-Muslim Egyptian Christian campaigner in the United States.
Michael reported from Cairo. Associated Press writer Esam Mohamed in Tripoli, Matthew Lee in Washington, Joseph Federman in Jerusalem and Sarah El Deeb in Cairo contributed to this report.