Yemeni security forces who rushed to the scene fired in the air and used tear gas to disperse the demonstrators, driving them out of the compound after about 45 minutes and sealing off the surrounding streets.
The Embassy said nobody was harmed in the attack. "All embassy personnel are safe and accounted for," spokesman Lou Fintor said.
Hadi, the president, offered his "sincere apologies" for the attack and promised to catch those behind it. He said the attack was carried out by a "rowdy crowd" as part of a conspiracy to derail Yemen's close relations with Washington.
The assault appeared to be a copy-cat of the protest Tuesday night at the U.S Embassy in Cairo, when angry youths climbed the walls and brought down the flag, though they largely refrained from any material damage.
Yemen is home to al-Qaida's most active branch and the United States is the main foreign supporter of the Yemeni government's counterterrorism campaign. The government on Tuesday announced that al-Qaida's No. 2 leader in Yemen was killed in an apparent U.S. airstrike, a major blow to the terror network.
The spreading violence comes as outrage grows over a movie called "Innocence of Muslims" produced by anti-Islam campaigners in the U.S. that mocked Islam's Prophet Muhammad. The amateurish video was produced in the U.S. and excerpted on YouTube. It depicts Muhammad as a fraud, a womanizer and a madman in an overtly ridiculing way, showing him having sex and calling for massacres.
Egyptian protesters clashed Thursday with police near the U.S. Embassy in Cairo. Police used tear gas to disperse the protesters and the two sides pelted each other with rocks. But unlike Tuesday, the police kept the protesters away from the embassy's compound.
The Interior Ministry, which is in charge of police, said 16 protesters and 13 policemen were wounded in the clashes, which broke out overnight and were ongoing. Twelve protesters have been arrested, it said.
Egyptian President Mohammed Morsi, speaking while on a visit to Brussels, vowed on Thursday not to allow attacks on foreign embassies in Cairo, saying the Egyptian people reject such "unlawful acts."
Afghanistan's government, meanwhile, sought to avert any protests as past anger over perceived insults to Islam has triggered violence in the country.
President Hamid Karzai canceled an official visit to Norway and spoke by phone with U.S. President Barack Obama to convey his condolences for the deaths of the U.S. ambassador to Libya and three other diplomats, a statement said. He also discussed the "film and the insulting of holy Islamic values," but the statement provided no other details.