The attack happened on Tuesday night, which was the 11th anniversary of 9/11.

It followed another earlier in the day on the American embassy in Cairo, in which no-one was injured but the flag was taken down and torn up and replaced with the black flag used by radical Islamists.

The violence was condemned by Hillary Clinton, the US secretary of state, who confirmed the death of a State Department official. "We are heartbroken by this terrible loss," she said. She said that in light of the attacks the US would be stepping up protection of "our personnel, our missions, and American citizens worldwide".

A vehicle sits smoldering in flames after being set on fire inside the US consulate compound in Benghazi (AFP/Getty Images)

The mobs involved in both embassy attacks were mainly comprised of Salafis, followers of an ultra-traditionalist approach to Islam that has spread across North Africa as well as much of the rest of the Arab world from Saudi Arabia in recent years.

Although they were not the prime movers in the "Arab Spring" protests, they have become much more visible in countries like Libya where secular dictators have been overthrown.

They are incensed by a film made in America and promoted on Youtube entitled "The Innocence of Muslims" that is intended to expose the "hypocrisy" of Islam. It not only portrays the Prophet, which the religion prohibits, but ridicules him as a homosexual and advocate of paedophilia, and shows him having sex.

It was apparently made by an Israeli-American businessman and backed by Terry Jones, the fundamentalist pastor who previously threatened to hold public burnings of the Koran. A version of the film, which is in English, has been dubbed into Egyptian Arabic and shown on the website of an Egyptian Coptic Christian businessman based in America.

Egyptian protesters tear down the US flag at the US embassy in Cairo (AFP/Getty Images)

In Cairo, the protests started on Tuesday afternoon, with hundreds of Salafists attacking and some climbing the fortress-like walls of the embassy. They did not enter the building itself, but one man managed to bring down the Stars and Stripes flag and replace it with a black flag with the Islamic inscription "There is no God but Allah and Mohammed is His Prophet".

That flag has become associated with Salafism, though other Islamist groups have used it in the Arab Spring.

The attack in Benghazi, which last year was the launch-pad of the revolution which overthrew Col Muammar Gaddafi and is a seat of Islamist politics in Libya, took place later in the evening.

Flames and smoke pour from the US Consulate in Benghazi (REUTERS)

The mob there was armed and sprayed the Libyan security forces defending the building with gunfire, and even shot rocket-propelled grenades. Overwhelming the defences, they then proceeded to hurl small home-made bombs at the buildings, loot it and then set it on fire.

But Mitt Romney, the Republican presidential candidate, said: ""I'm outraged by the attacks on American diplomatic missions in Libya and Egypt and by the death of an American consulate worker in Benghazi.

"It's disgraceful that the Obama Administration's first response was not to condemn attacks on our diplomatic missions, but to sympathize with those who waged the attacks."