It was the first time ever that the U.S. Embassy in Cairo has been breached and comes as Egypt is struggling to overcome months of unrest following the ouster of Hosni Mubarak's autocratic regime. U.S. officials said no Americans were reported harmed in the assaults in Cairo or the eastern city of Benghazi.
The unrest in Cairo began when hundreds of protesters marched to the downtown embassy, gathering outside its walls and chanting against the movie and the U.S.
"Say it, don't fear: Their ambassador must leave," the crowd chanted.
Dozens of protesters then scaled the embassy walls, and several went into the courtyard and took down the flag from a pole. They brought it back to the crowd outside, which tried to burn it, but failing that tore it apart.
The protesters on the wall then raised on the flagpole a black flag with a Muslim declaration of faith, "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.
The crowd grew throughout the evening with thousands standing outside the embassy. Dozens of riot police lined up along the embassy walls but did not stop protesters as they continued to climb and stand on the wall - though it appeared no more went into the compound.
The crowd chanted, "Islamic, Islamic. The right of our prophet will not die." Some shouted, "We are all Osama," referring to al-Qaida leader bin Laden. Young men, some in masks, sprayed graffiti on the walls. Some grumbled that Islamist President Mohammed Morsi had not spoken out about the movie.
A group of women in black veils and robes that left only their eyes exposed chanted, "Worshippers of the Cross, leave the Prophet Muhammad alone."
By midnight, the crowd had dwindled. The U.S. Embassy said on its Twitter account that there will be no visa services on Wednesday because of the protests.
A senior Egyptian security official at the embassy area said authorities allowed the protest because it was "peaceful." When they started climbing the walls, he said he called for more troops, denying that the protesters stormed the embassy. He spoke on condition of anonymity because he was not authorized to speak to reporters.
The protest was sparked by outrage over a video being promoted by an extreme anti-Muslim Egyptian Christian campaigner in the United States. A 14-minute trailer of the movie, posted on the social website YouTube in an original English version and another dubbed into Egyptian Arabic, depicts Muhammad as a fraud, a womanizer and a madman in an overtly ridiculing way, 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 2005 publication of 12 caricatures of the prophet Muhammad in a Danish newspaper triggered riots in many Muslim countries.
In a sign of growing anger over the film, Libyans set fire to the U.S. 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.
The Cairo embassy is in a diplomatic area in Garden City, where the British and Italian embassies are located, only a few blocks away from Tahrir Square, the center of last year's uprising that led to the ouster of Hosni Mubarak. The U.S. Embassy is built like a fortress, with a wall several meters (yards) high. But security has been scaled back in recent months, with several roadblocks leading to the facility removed after legal court cases by residents.
The Egyptian Foreign Ministry promised in a statement to provide the necessary security for diplomatic missions and embassies and warned that "such incidents will negatively impact the image of stability in Egypt, which will have consequences on the life of its citizens."
One protester, Hossam Ahmed, said he was among those who entered the embassy compound and replaced the American flag with the black one. He said the group has now removed the black flag from the pole and laid it instead on a ladder on top of the wall.
"This is a very simple reaction to harming our prophet," said another, bearded young protester, Abdel-Hamid Ibrahim.
In Washington, State Department spokeswoman Victoria Nuland said Egyptian police had removed the demonstrators who entered the embassy grounds. She also condemned the attack on the consulate in Libya "in the strongest terms."
Only a few staff members were inside the embassy in Cairo, as embassy security had sent most staff home early after learning of the upcoming protest, a U.S. official said, speaking on condition of anonymity because he wasn't authorized to speak publicly on the matter.
Sam Bacile, an American citizen who said he produced, directed and wrote the two-hour film, said he had not anticipated such a furious reaction.
"I feel sorry for the embassy. I am mad," Bacile said.
Speaking from a telephone with a California number, he said the film was produced in English and he doesn't know who dubbed it in Arabic. The full film has not been shown yet, he said, and he said he has declined distribution offers for now.
"My plan is to make a series of 200 hours" about the same subject, he said.
Morris Sadek, an Egyptian-born Christian in the U.S. known for his anti-Islam views, told The Associated Press from Washington that he was promoting the video on his website and on certain TV stations, which he did not identify.
Both depicted the film as showing how Coptic Christians are oppressed in Egypt, though it goes well beyond that to ridicule Muhammad - a reflection of their contention that Islam as a religion is inherently oppressive.
"The main problem is I am the first one to put on the screen someone who is (portraying) Muhammad. It makes them mad," Bacile said, speaking English with an Egyptian accent, though he would not answer when asked if he was of Egyptian origin. "But we have to open the door. After 9/11 everybody should be in front of the judge, even Jesus, even Muhammad."
For several days, Egyptian media have been reporting on the video, playing some excerpts from it and blaming Sadek for it, with ultraconservative clerics going on air to denounce it.
Medhat Klada, a representative of Coptic Christian organizations in Europe, said Sadek's views are not representative of expatriate Copts.
"He is an extremist ... We don't go down this road. He has incited the people (in Egypt) against Copts," he said, speaking from Switzerland. "We refuse any attacks on religions because of a moral position."
But he said he was concerned about the backlash from angry Islamists, saying their protest only promotes the movie. "They don't know dialogue and they think that Islam will be offended from a movie."
Associated Press writer Bradley Klapper in Washington and Esam Mohamed in Tripoli, Libya contributed to this report.