TRIPOLI—The U.S. ambassador to Libya, Chris Stevens, and three State Department officials were killed last night in a targeted rocket attack, after riots over a U.S. film depicting the Prophet Muhammad as a fraud. The assault came as the envoy sought to reach safety during a vicious Salafist assault on the American consulate in the eastern Libyan city of Benghazi, leading to a fierce five-hour fight that saw Libyan security withdraw under the intensity of the gunfire, according to Libyan officials. President Obama confirmed the deaths, calling them "outrageous."

Libyan officials say Stevens was killed when his car was targeted deliberately as he and some staffers tried to move to safety following the initial attacks on the consulate. He is only the sixth serving U.S. ambassador ever to be killed while on duty. The attack involving dozens of gunmen from the Islamist Ansar al-Sharia group as well as other militants saw fierce clashes between them and U.S. guards and Libyan security units.

One of the American State Department employees may have died of smoke inhalation from the fire at the consulate, according to U.S officials. Another appears to have been killed in the exchange of gunfire. Gunmen, armed with semiautomatic weapons and rocket-propelled grenades, shot at the building and threw handmade bombs into the compound. They eventually took over the building when Libyan security units and police withdrew under the intensity of the attack, according to Abdel-Monem Al-Hurr, spokesman for Libya's Supreme Security Committee.

European missions in Libya were put on high alert today, ramping up their security arrangements and ordering staff to avoid all but essential travel, and several U.S. and European NGOs and other international missions considered whether they should evacuate staff from Libya following the killings, which have emphasized how unstable and lawless the country is becoming with the central government unable to enforce its will.

The violence in Benghazi coincided with furious protests in neighboring Egypt. About 2,000 protesters scaled the walls of the U.S. embassy in Cairo, tearing down an American flag and burning it. Yesterday was also the 11th anniversary of 9/11 and, while the focus of the attacks in Benghazi and Cairo was on a U.S. movie ridiculing the Prophet Muhammad, the demonstrators railed also against the U.S. generally, decrying the post-9/11 U.S.-led invasions of Iraq and Afghanistan and American support for Israel.

The president of the Libyan General Congress, Mohamed Yussef Magariaf, promised to coordinate additional support to protect Americans and other Westerners working in Libya. He pledged his government's full cooperation and this morning held emergency talks with Libyan ministers. Ironically, today was meant to have been a landmark day for the country’s fragile and violence-marked transition from autocracy to democracy with the announcement of who would be Libya’s first postelection prime minister after voting in the new Parliament.

Stevens was a noted Arabist and became ambassador in June. He had served in Tripoli as the deputy ambassador before the rebellion that ousted Col. Gaddafi last year. He was the Obama administration’s liaison with the Libyan opposition during the rebellion.

Libyan government officials acknowledged the connection between the Benghazi violence and the protests in Cairo. "There is a connection between this attack and the protests that have been happening in Cairo,“ said Hurr, the Libyan security spokesman.

Watch a clip of the movie 'Innocence of Muslims,' which sparked the attacks.

In Cairo protesters replaced the U.S. flag with the black flag of Islamic militancy. Mohamed al-Zawahiri, the brother of al Qaeda leader Ayman al-Zawahiri, was among the protesters in the Egyptian capital, where demonstrators chanted “Obama! Obama! We are all Osama!” The younger Zawahiri was released from an Egyptian prison jail earlier this year after serving 10 years on charges of militancy.

Earlier on Tuesday, scholars at Egypt’s influential Al-Azhar mosque condemned the film ridiculing Prophet Muhammad produced by an Israeli-American real-estate developer in California, Sam Bacile, and promoted by among others Florida-based Christian evangelist Terry Jones, whose burning of a Quran sparked riots in Afghanistan in 2011. The condemnation and news about the movie moved like wildfire across Islamist Facebook pages. Salafi preachers took to Islamist satellite channels to add their fury.

The two-hour film of a symbolic "trial" of the Muslim prophet has not been shown yet, but a 14-minute trailer of the movie was posted on YouTube both in an English version and another dubbed into Arabic. The movie, Innocence of Muslims, depicts Muhammad as a fraud and a womanizer. Bacile told reporters that he doesn’t know who dubbed the film. Terry Jones said that the film shows “the destructive ideology of Islam,” adding that the attacks in Benghazi and Cairo demonstrate that Muslims “have no tolerance.”

Secretary of State Hillary Clinton said in a statement released hours after the attacks that while deploring “any intentional effort to denigrate the religious beliefs of others,” there is “never any justification for violent acts of this kind." Her statement was issued before confirmation of the ambassador’s death.

Libyan officials seemed embarrassed that they had been unable to hold back militants from storming and wrecking the U.S. consulate in Benghazi—in contrast to the Egyptian security forces, who were able to prevent the U.S. embassy buildings in Cairo from being penetrated. But they say that in Cairo the protesters did not come heavily armed and ready for a battle. “The Libyan security forces came under heavy fire, and we were not prepared for the intensity of the attack," Libyan security spokesman Hurr said.

Wanees Sharef, a Libyan government minister, said the militants in Benghazi arrived with the clear intention of causing the maximum amount of damage and that a government brigade that battled with them had no choice but to withdraw and allow them to take over the building.

Libya's interim government has struggled to impose its authority on the country since the ouster last year of Col. Gaddafi. There are estimated to be about 200,000 militia fighters in the country, and militias remain a law unto themselves. Benghazi has been the scene of other attacks this year on Western targets, including an attempt to assassinate the British ambassador. The International Red Cross building came under a grenade attack, and earlier in the summer a small handmade bomb was hurled at the U.S. consulate.

Ultraconservative Muslims in recent weeks have unleashed a wave of sectarian violence across Libya, involving bombings and the destruction of historic mosques and shrines revered by Sufi Muslims, saying they aim to rid the country of all Sufi landmarks. They’ve also started to turn their attention to women, posting flyers at universities and private schools insisting male and female students are segregated. While Salafists, followers of the Saudi-inspired ultratraditionalist approach to Islam, were not key in the ousting of Gaddafi, they have grown in strength and audacity in recent months, as in other parts of North Africa, recruiting from revolutionary militias and among the young who increasingly feel the Arab Spring has failed to deliver.