Washington – The Obama administration suspects that the fiery attack in Libya that killed the American ambassador and three other diplomats may have been planned rather than a spontaneous mob getting out of control, American officials said Wednesday.

Officials in Washington studying the events of the past 24 hours have focused on the differences between the protests on the American embassy in Cairo and the attack on the consulate in Benghazi, the Libyan city where Ambassador J. Christopher Stevens and the other Americans were killed.

The protesters in Cairo appeared to be a genuinely spontaneous unarmed mob angered by an anti-Islam video produced in the United States. By contrast, it appeared the attackers in Benghazi were armed with mortars and rocket-propelled grenades. Intelligence reports are inconclusive at this point, officials said, but indications suggest the possibility that an organized group had either been waiting for an opportunity to exploit like the protests over the video or perhaps even generated the protests as a cover for their attack.

President Obama strongly condemned the killings and ordered increased security at American diplomatic posts around the world. American defense officials said 50 Marines were en route to Libya to strengthen security at United States diplomatic facilities, and the State Department ordered all “nonemergency” personnel out of the country and warned Americans not to go there, suggesting that further attacks were possible.

The death of Mr. Stevens was the first of an American envoy abroad in more than two decades.

“These four Americans stood up for freedom and human dignity,” Mr. Obama said in a televised statement from the White House Rose Garden, where he stood with Secretary of State Hillary Rodham Clinton. “Make no mistake: we will work with the Libyan government to bring to justice the killers who attacked our people.”

Mr. Obama also offered praise for the Libyan government, noting that Libyan security forces fought back against the mob, helped protect American diplomats and took Mr. Stevens’s body to the hospital. “This attack will not break the bonds between the United States and Libya,” he said.

The attack at the compound in Benghazi was far more deadly than administration officials first announced on Tuesday night, when Mrs. Clinton said one American had been killed and one injured.

Another of those killed was Sean Smith, an information management officer who joined the Foreign Service 10 years ago, Mrs. Clinton said in a statement. The State Department did not identify the other two, pending notification of their relatives. Mr. Smith, who was a husband and father of two, previously served in Iraq, Canada and the Netherlands.

Neither Mr. Obama nor Mrs. Clinton disclosed details of the attack, and it was unclear precisely how Mr. Stevens or the others had died.

Mr. Stevens took up his ambassador post in May after having served as an envoy to the Libyan rebels who overthrew Libya’s leader, Col. Muammar el-Qaddafi, last year. He was widely admired by the Libyan rebels for his support of their struggle.

“While the United States rejects efforts to denigrate the religious beliefs of others, we must all unequivocally oppose the kind of senseless violence that took the lives of these public servants,” Mr. Obama said, calling Mr. Stevens “a courageous and exemplary representative of the United States” who had “selflessly served our country and the Libyan people at our mission in Benghazi” and, as ambassador, “supported Libya’s transition to democracy.”

The killings put an enormous new strain on Washington’s relations with the new Libyan government that took over after the ouster of Colonel Qaddafi, and they threatened to sour American public opinion about the prospects of the democratic opening of the Arab Spring.

The news of the deaths emerged on Wednesday after violence spilled over the American Consulate in Benghazi and demonstrators stormed the fortified walls of the American Embassy in Cairo. Anti-American protests also were reported in Gaza, and the Taliban in Afghanistan called on Afghans to “take revenge” on American targets there.

Few details of the way events unfolded in Benghazi were immediately available, but the killing of the ranking American official in Libya raised questions about the vulnerability of American officials at a time when the profound changes sweeping the Arab world have hardly dispelled the rage against the United States that still smolders in pockets around the region.

The president of Libya’s National Assembly, Mohammed Magarief, apologized for the attack, describing it as “cowardly” and offering condolences, The Associated Press reported. Speaking to reporters, he said the culprits would be brought to justice and pledged to maintain close relations with the United States.

Tuesday’s violence came on the 11th anniversary of the terrorist attacks of Sept. 11, 2001, and was initially attributed to anger over a 14-minute trailer for the American video, called “Innocence of Muslims,” that was released on the Web. The violence provoked by the video, which was publicized in recent days by the Egyptian media, recalled the wave of rage and protest in 2005 that followed the publication of 12 cartoons in a Danish newspaper lampooning the Prophet Muhammad.

An unidentified Libyan official in Benghazi told Reuters that Mr. Stevens and three staff members were killed in Benghazi “when gunmen fired rockets at them.” It was not clear where in the city the attack took place. The Libyan official said the ambassador was being driven from the consulate building to a safer location when gunmen opened fire, Reuters said.

Agence France-Presse quoted the Libyan Interior Ministry as saying that Mr. Stevens and the three staff members were killed when a mob attacked the consulate in Benghazi. Al Jazeera’s English-language Web site said Mr. Stevens died of smoke inhalation after a mob set fire to the building, and a Libyan physician who treated Mr. Stevens at the hospital was quoted by The Associated Press as saying he had tried to revive him for 90 minutes.

In Italy, the Web site of the newspaper Corriere della Sera showed images of what it said was the American Consulate in Benghazi ablaze with men carrying automatic rifles and waving V-for-victory signs, silhouetted against the burning buildings. One photograph showed a man closely resembling Mr. Stevens apparently unconscious, his face seeming to be smudged with smoke and his eyes closed.

Mr. Stevens, conversant in Arabic and French, had worked at the State Department since 1991 after a spell as an international trade lawyer in Washington. He taught English as a Peace Corps volunteers in Morocco from 1983 to 1985, the State Department Web site said.

According to the State Department, five American ambassadors had been killed by terrorists before the attack on the American consulate in Benghazi. The most recent was Adolph Dubs, killed after being kidnapped in Afghanistan in 1979. The others were John Gordon Mein, in Guatemala in 1968; Cleo A. Noel Jr., in Sudan in 1973; Rodger P. Davies, in Cyprus in 1974; and Francis E. Meloy Jr., in Lebanon in 1976.

In the violence in Benghazi on Tuesday, protesters with automatic rifles and rocket-propelled grenades attacked the American Consulate and set it on fire, Libyan officials said. Some news reports said American guards inside the consulate had fired their weapons, and a brigade of Libyan security forces arriving on the scene had battled the attackers in the streets as well.

In Cairo, thousands of unarmed protesters had gathered outside the American embassy during the day. By nightfall, some had climbed over the wall around the embassy compound and destroyed a flag hanging inside. The vandals replaced it with a black flag favored by ultraconservatives and militants and labeled with the most basic Islamic profession of faith: “There is no god but God, and Muhammad is his prophet.” Embassy guards fired guns into the air, but a large contingent of Egyptian riot police officers on hand to protect the embassy evidently did not use their weapons against the crowd, and the protest continued, largely without violence, into the night.

A spokesman for the Muslim Brotherhood, the mainstream Islamist group and the sponsor of Egypt’s first elected president, Mohamed Morsi, urged the United States government on Tuesday to prosecute the “madmen” behind the video, according to the English-language Web site of the state newspaper, Al Ahram.

The spokesman asked for a formal apology from the United States government and warned that events like the video were damaging Washington’s relations with the Muslim world. He also emphasized that any protests should remain peaceful and respect property.

There should be “civilized demonstrations of the Egyptian people’s displeasure with this film,” the Brotherhood spokesman said, according to the newspaper Web site. “Any nonpeaceful activity will be exploited by those who hate Islam to defame the image of Egypt and Muslims.”

Bracing for trouble before the start of the protests here and in Libya, the American Embassy released a statement shortly after noon that appeared to refer to Terry Jones, a Florida pastor who promoted the video: “The United States Embassy in Cairo condemns the continuing efforts by misguided individuals to hurt the religious feelings of Muslims — as we condemn efforts to offend believers of all religions.” It later denounced the “unjustified breach of our embassy.”

Peter Baker reported from Washington, David D. Kirkpatrick from Cairo and Alan Cowell from London. Reporting was contributed by Suliman Ali Zway from Tripoli, Libya; Steven Lee Myers, John H. Cushman Jr. and Elisabeth Bumiller from Washington; Rachel Donadio from Rome; Isabel Kershner from Jerusalem; and Christine Hauser and Rick Gladstone from New York.

This article has been revised to reflect the following correction:

Correction: September 12, 2012: An earlier version of this article referred imprecisely to the title of Mohammed Magarief. He is the president of Libya’s National Assembly, not Libya’s interim president.

This story, “US Suspects Libya Attack Was Planned,” originally appears at the New York Times News Service.

