Gunmen had attacked and burned the U.S. consulate in the eastern city of Benghazi, a centre of last year's uprising against Muammar Gaddafi, late on Tuesday evening, killing one U.S. consular official. The building was evacuated.
The Libyan official said the ambassador, Christopher Stevens, was being driven from the consulate building to a safer location when gunmen opened fire.
"The American ambassador and three staff members were killed when gunmen fired rockets at them," the official in Benghazi told Reuters.
There was no immediate comment from the State Department in Washington. U.S. ambassadors in such volatile countries are accompanied by tight security, usually travelling in well-protected convoys. Security officials will be considering whether the two attacks were coordinated.
Libyan deputy prime minister Mustafa Abu Shagour condemned the killing of the U.S. diplomats as a cowardly act.
The consular official had died after clashes between Libyan security forces and Islamist militants around the consulate building. Looters raided the empty compound and some onlookers took pictures after calm returned.
In neighbouring Egypt, demonstrators had torn down an American flag and burned it during the protest. Some tried to raise a black flag with the words "There is no God but God, and Mohammad is his messenger", a Reuters witness said.
PORTRAYAL OF PROPHET
U.S. pastor Terry Jones, who had inflamed anger in the Muslim world in 2010 with plans to burn the Koran, said he had promoted "Innocence of Muslims", which U.S. media said was produced by an Israeli-American property developer; but clips of another film called "Mohammad, Prophet of Muslims", had been circulating for weeks before the protest.
That film portrayed Mohammad as a fool, a philanderer and a religious fake.
Jones, a pastor in Florida whose latest stunt fell on the anniversary of the Sept. 11, 2001, attacks on the World Trade Center and the Pentagon, triggered riots in Afghanistan in 2010 with his threat to burn the Koran.
For Muslims, any depiction of the Prophet offensive.
Libya's interim government has struggled to impose its authority on a myriad of armed groups that have refused to lay down their weapons and often take the law into their own hands.
It was clearly overwhelmed by Tuesday night's attack on the consulate that preceded the assault on the ambassador.
"The Libyan security forces came under heavy fire and we were not prepared for the intensity of the attack," said Abdel-Monem Al-Hurr, spokesman for Libya's Supreme Security Committee.
In Benghazi, unidentified men had shot at the consulate buildings, while others threw handmade bombs into the compound, setting off small explosions.
U.S. Secretary of State Hillary Clinton, in a statement late on Tuesday, confirmed the death of the U.S. consular diplomat in Libya, who was not identified, and condemned the attack there; but she made no mention of an attack on the Ambassador's car.