The state department said the US was working with Egyptian authorities to try to restore order Reuters

Egyptian protesters, largely ultraconservative Islamists, climbed the walls of the US embassy in Cairo on Tuesday, made their way into the courtyard and brought down the flag, replacing it with a black flag with an Islamic inscription to protest a film attacking Islam's prophet, Muhammad.

Hours later, armed men in eastern Libya also stormed the US consulate there and set it on fire as anger spread.

Hundreds of protesters marched to the embassy in central Cairo, gathering outside its walls and chanting against the movie, which was reportedly produced in the United States.

"Say it, don't fear: their ambassador must leave," the crowd chanted.

Dozens of protesters then scaled the embassy walls, took down the flag from a pole in the courtyard and brought it back to the crowd outside. The crowd tried to burn it, but failing that, tore it apart. The protesters on the wall then raised on the flagpole a black flag with the Muslim declaration of faith on it: "There is no god but God and Muhammad is his prophet." The flag, similar to the banner used by al-Qaida, is commonly used by ultraconservatives around the region.

In Washington, state department spokeswoman Victoria Nuland said the US was working with Egyptian authorities to try to restore order.

Almost all the staff had left before the embassy was breached, a US official said. Only a few staff members were still inside, as embassy security had sent most staff home early after learning of the upcoming protest. The situation is still fluid, said the official, who spoke on condition of anonymity because he wasn't authorized to speak publicly on the matter.

An official in the embassy in Cairo said the ambassador was out of town.

Egyptian media say the movie was recently produced in the United States by an anti-Muslim group. The film, clips of which are available on YouTube, depicts Muhammad as a fraud, showing him having sex and calling for massacres. Muslims find it offensive to depict Muhammad in any fashion, much less in an insulting way.

The protests came after some Egyptian media have been reporting on the film for several days, with ultraconservative clerics going on air to denounce it.

In a sign of growing anger over the film, Libyans set fire to the US consulate in the eastern city of Benghazi and fired in the air after a protest against the film. Witnesses said much of the consulate was burned.