CAIRO (CNN) -

The United States said it was taking measures to protect its citizens worldwide after protesters angry about an online film considered offensive to Islam attacked U.S. diplomatic compounds in Libya and Egypt Tuesday.

In Libya, witnesses say members of a radical Islamist group called Ansar al-Sharia protested near the U.S. Consulate in Benghazi, where NATO jets established no-fly zones last year to halt ground attacks from then-Libyan strongman Moammar Gadhafi.

The group then clashed with security forces in the city, blocking roads leading to the consulate, witnesses said.

The U.S. ambassador to Libya, J. Christopher Stevens, was killed in the attack, the State Department said. Sean Smith, a Foreign Service information management officer, and two other U.S. personnel also died in the violence in Benghazi, Secretary of State Hillary Clinton said in a statement Wednesday.

"Our hearts go out to all their families and colleagues," Clinton said.

"All the Americans we lost in yesterday's attacks made the ultimate sacrifice. We condemn this vicious and violent attack that took their lives, which they had committed to helping the Libyan people reach for a better future," she added.

In an earlier statement, Clinton said she condemned the attack on the U.S. facilities "in the strongest terms" and that following Tuesday's events, the U.S. government was "working with partner countries around the world to protect our personnel, our missions and American citizens worldwide."

Libya's General National Congress also condemned the attack in Benghazi, saying it "led to the regrettable injury and death of a number of individuals." Lawmakers said in a statement Tuesday night that they were investigating.

It was unclear whether the two attacks were coordinated, CNN national security contributor Fran Townsend said Tuesday night.

"One such breach of an embassy or consulate's walls or security on any given day would be tremendous news. ... The fact that two of them happened on the same day that is the 9/11 anniversary where Americans are remembering those that we lost, you have to ask yourself, what are American officials trying to understand about this and whether or not these two are related?" she asked.

In Cairo, several men scaled the walls of the U.S. Embassy and tore down its American flag, according to CNN producer Mohamed Fadel Fahmy, who was on the scene.

Police and army personnel formed defensive lines around the embassy in an effort to prevent demonstrators from advancing, but not before the protesters affixed a black flag atop a ladder in the American compound.

The black flag, which hangs in full view from inside the complex, is adorned with white characters that read, "There is no God but Allah and Mohammed is his messenger," an emblem often used by Islamic radicals.

A volley of warning shots were fired as a large crowd gathered around the compound, although it is not clear who fired the shots.

Egyptian groups point to U.S. websites, including YouTube, that have scenes from the film. Some anti-Muslim blogs also have flagged the movie.

In a series of disjointed scenes, filmmakers depict Prophet Mohammed as a child molester, womanizer and ruthless killer.

The movie was made by Sam Bacile, an Israeli-American real-estate developer, according to the Wall Street Journal.

Bacile -- who wrote, directed and produced the film -- said he wanted to showcase his view of Islam as a hateful religion, the Journal reported, citing a telephone interview with him.

Bacile, 52, told the newspaper that to make the film, he had raised $5 million from about 100 Jewish donors, who he declined to identify. He said he made the two-hour movie over a three-month period last year in California, using about 60 actors and 45 crew members, the Journal reported.

Most of the Muslim world considers depictions of Mohammed to be blasphemous and deeply offensive.

"Some have sought to justify this vicious behavior as a response to inflammatory material posted on the Internet," Clinton said. "The United States deplores any intentional effort to denigrate the religious beliefs of others. Our commitment to religious tolerance goes back to the very beginning of our nation."

But she stressed that "there is never any justification for violent acts of this kind."

Embassy officials issued a warning to Americans in Egypt, telling them to avoid the demonstrations which "may gather in front of the U.S. Embassy, or Egyptian government buildings such as the People's Assembly and Ministry of Interior."

"It is unclear if large numbers will take to the streets, but clashes may occur should two opposing groups come into contact with one another," the U.S. Embassy said in a statement. "Large gatherings and non-essential travel in and around downtown and Garden City should be avoided this afternoon."

Frenzied protesters could been seen Tuesday afternoon holding up bits of a shredded American flag to television camera crews while chanting anti-U.S. slogans.