BENGHAZI, Libya — Heavily armed militants used a protest of an anti-Islam film as a cover and may have had help from inside Libyan security in their deadly attack on the U.S. Consulate, a senior Libyan official said Thursday.

As Libya announced the first four arrests, the clearest picture yet emerged of a two-pronged assault with militants screaming “God is great!” as they scaled the consulate’s outer walls and descended on the compound’s main building. The U.S. ambassador and three other Americans were killed in the rampage.

Eastern Libya’s deputy interior minister, Wanis el-Sharef, said a mob first stormed the consulate Tuesday night and then, hours later, raided a safe house in the compound just as U.S. and Libyan security arrived to evacuate the staff. That suggested, el-Sharef said, that infiltrators within the security forces may have tipped off the militants to the safe house’s location.

The attacks were suspected to have been timed to coincide with the 11th anniversary of the Sept. 11, 2001, terrorist strike in the United States, el-Sharef said, with the militants using the film protest by Libyan civilians to mask their action. But U.S. officials said they had yet to find direct evidence of a connection.

Killed in the attack were U.S. Ambassador Chris Stevens, information management officer Sean Smith, private security guard Glen Doherty and one other American who has yet to be identified.

El-Sharef said four people were arrested at their homes Thursday, but he refused to give any further details. He said it was too early to say if the suspects belonged to a particular group or what their motive was. Libya’s new prime minister, Mustafa Abu-Shakour, said authorities were looking for more suspects.

One of five private security guards at the consulate said the surprise attack began around 9:30 p.m. when several grenades that were lobbed over the outer wall exploded in the compound and bullets rained down.

The guard was wounded in the left leg from shrapnel. He said he was lying on the ground, bleeding and in excruciating pain, when a bearded gunman came down the wall and shot him twice in the right leg, screaming: “You infidel, you are defending infidels!”

“Later, someone asked me who I was. I said I was the gardener and then I passed out. I woke up in the hospital,” said the guard, who spoke to The Associated Press from his bed at a Benghazi hospital. He spoke on condition of anonymity because he feared reprisals and reprimands from his employers.

Speaking at his Benghazi office, el-Sharef, who was running the Interior Ministry’s operations room commanding security forces in the city during the attack, gave the most detailed account to date to come out of Libya of what happened the night of the attack. His version, however, leaves some questions unanswered and does not provide a definitive explanation on the motives behind the attack and the identity of the perpetrators.

No one has claimed responsibility for the attack. Some Libyan officials have pointed the finger at a hardline Islamist militia, the Ansar al-Shariah Brigades, one of multiple Libyan militias operating in the city. A spokesman for the group lavishly praised the assault for “protecting the faith and fighting for the victory of God Almighty.” But he said the Brigades “did not participate as an organization. This was a popular uprising.”

Adding to the confusion surrounding the attack is that it targeted the United States, a nation that played a key role in ridding the oil-rich nation of dictator Moammar Gadhafi.

Stevens was credited by most Libyans with organizing a political front made up of opposition groups to unite the uprising against Gadhafi’s 41-year rule, mediating tribal and regional disputes.

The Benghazi attack also underlined the precarious conditions in Libya nearly a year after Gadhafi’s fall, with a weak central government, militias operating as local governments, a destabilizing proliferation of weapons, and militant groups — some inspired by al-Qaida — that are active under the government’s radar.

Stevens and another American were killed in the consulate during the initial violence, as plainclothes Libyan security were evacuating the consulate’s staff to the safe house about a mile away, el-Sharef said. The second assault took place several hours later and targeted the safe house — a villa inside the grounds of the city’s equestrian club — killing two Americans and wounding a number of Libyans and Americans.

The crowd built at the consulate — a one-story villa surrounded by a large garden in an upscale Benghazi neighborhood — in several stages, El-Sharef said. First, a small group of gunmen arrived, then civilians angry over the film. Later, heavily armed men with armored vehicles, some with rocket-propelled grenades, joined and the numbers swelled to more than 200.

The gunmen fired into the air outside the consulate. Libyan security guarding the site pulled out because they were so outmanned. “We thought there was no way for the protesters to storm the compound, which had fortified walls,” he said.

Libyan security advised the Americans to evacuate at that point, but the advice was ignored, he said. There was shooting in the air from inside the consulate compound, El-Sharef said.

At this point, el-Sharef continued, the crowd stormed the compound. The consulate was looted and burned, while plainclothes security men were sent to evacuate the personnel.

Stevens probably died of asphyxiation following a grenade explosion that started a fire, el-Sharef said, echoing what the Libyan doctor to whom Stevens’ body was taken told the AP on Wednesday.

His account was corroborated by local journalist Ibrahim Hadya, who was at the scene. He told the AP that the consulate was stormed just as the evacuation was under way, with staff members smuggled out a side door that opens to a street other than the one where the militants and protesters gathered.

U.S. officials have said attackers broke into the main consulate building around 10:15 p.m. and set the compound on fire. Amid the evacuation, Stevens became separated from others, and staffers and security who tried to find him were forced to flee by flames, smoke and gunfire. After an hour, according to U.S. officials, U.S. and Libyan officials drove the attackers from the consulate.