The American ambassador to Libya, J. Christopher Stevens, and three officials were killed when a mob attacked the US consulate in the eastern city of Benghazi, the interior ministry said Wednesday.
"The ambassador was killed along with three other officials," said Wanis al-Sharif, the deputy minister of the interior.
Stevens' death in Tuesday's attack was confirmed in a tweet by Mustafa Abu Shagur, the deputy prime minister.
Stevens, a career officer with the US foreign service, had been in the country for less than four months after taking up his post in the capital Tripoli in May.
Fawzi Wanis, who heads the High Security Commission in Benghazi, confirmed that Stevens was at the consulate when it was attacked.
The envoy died when an armed mob protesting against a film deemed offensive to Islam attacked the US mission, just hours after Islamists also stormed Washington's embassy in the Egyptian capital Cairo.
The film at the centre of the anti-US protests was made by an Israeli-American who describes Islam as a "cancer" and depicts the Prophet Mohammed sleeping with women, the Wall Street Journal reported.
Before confirmation of Stevens' death, US Secretary of State Hillary Clinton announced that a State Department official had been killed in the attack on the consulate, saying: "We are heartbroken by this terrible loss."
Abdelmonoem al-Horr, spokesman for the Libyan interior ministry's security commission, earlier said rocket-propelled grenades were fired at the consulate from a nearby farm.
Witnesses said the attackers ripped up a US flag, then looted the consulate before setting it on fire on the eleventh anniversary of the September 11 attacks.
"Dozens of demonstrators attacked the consulate and set fire to it," said a Benghazi resident, who only gave his name as Omar, adding that he had seen the flames and heard shots in the vicinity.
Another Libyan witness said armed men, including ultra-conservative Salafists, had closed the streets leading up to the consulate.
The violent protest was strongly condemned by Libya's General National Congress, which in a statement expressed "outrage at the unfortunate attack against the American consulate in Benghazi."
The Libyan incident came after thousands of Egyptian demonstrators Tuesday tore down the Stars and Stripes at the US embassy in Cairo and replaced it with a black Islamic flag, similar to one adopted by several militant groups.
Nearly 3,000 demonstrators, most of them hardline Islamist supporters of the Salafist movement, gathered at the embassy in protest over the film, which was produced in the United States.
A dozen men scaled the embassy walls and one of them tore down the US flag, replacing it with a black one inscribed with the Muslim profession of faith: "There is no God but God and Mohammed is the prophet of God."
Egyptian police intervened without resort to force and persuaded the trespassers to come down. The crowd then largely dispersed leaving just a few hundred protesters outside the US mission, an AFP correspondent reported.
An Egyptian security official said on Wednesday that security has been stepped up in the area around the US embassy in Cairo following the protests.
"There is an increased security presence in central Cairo, particularly around the American embassy," the official told AFP, adding that no arrests had been made during Tuesday's demonstration.
Coptic activists said they would stage a vigil on Wednesday in protest against the film.
The Maspero Youth Union (MYU) and the Coalition of Coptic Egypt condemned "all sorts of contempt or disdain against any religion, as well as to the sowing of sedition between people who embrace different religions," the statement said.
The movie, "Innocence of Muslims," was directed and produced by Sam Bacile, a 52-year-old real-estate developer from southern California.
"Islam is a cancer," Bacile told the Wall Street Journal of his crudely-produced film, which depicts the Prophet Mohammed variously sleeping with women, talking about killing children and referring to a donkey as "the first Muslim animal."
The film is being promoted by controversial Florida pastor Terry Jones, who has drawn protests in the past for burning the Koran and vehemently opposing the construction of a mosque near Ground Zero in New York.
In Washington, Clinton said she had spoken with Libyan leader Mohamed al-Megaryef to coordinate extra support to help protect Americans working in Libya, and he had pledged his full cooperation.
"In light of the events of today, the United States government is working with partner countries around the world to protect our personnel, our missions, and American citizens worldwide," Clinton said.
Tuesday's protests came on the eleventh anniversary of the attacks of September 11, 2001, when US cities were targeted by hijacked planes.
Benghazi, a stronghold of Islamist extremists and cradle of the revolution that saw strongman Moamer Kadhafi captured and killed last year, has seen a wave of violence in recent months, including attacks on Western targets, bombings of military buildings and the killings of army and security officers.
Interior Minister Fawzi Abdelali has warned that Islamists amount to a "major force" in Libya both in terms of numbers and arms.