CAIRO—It was a bloody ordeal with tick-tock drama and a watching world.

The hostages at a gas refinery in the Sahara desert faced four harrowing days trapped between two dangers: Islamist militants, who forced some of them into wearing explosives belts, and the Algerian commandos, who showed no inclination to negotiate for their release.

After the army carried out its “final assault” Saturday, Algerian officials said that at least 23 hostages and 32 militants had been killed since gunmen startled the world by storming the remote gas plant in the pre-dawn hours Wednesday.

The horrors of the days that followed were described by survivors, many of them expatriates working at Ain Amenas in eastern Algeria.

Ruben Andrada, 49, a Filipino engineer, said he and colleagues were used as human shields by the kidnappers but that did little to deter the Algerian military.

On Thursday, he said, 15 militants loaded him and about 35 hostages into seven SUVs to move them in a convoy from the housing complex to the refinery. “An explosive cord” was placed around their necks and they were told it would detonate if they tried to run away.

But as the convoy set off, Algerian military helicopters opened fire with guns and missiles to stop what they thought was an escape attempt, resulting in many deaths.

“When we left the compound, there was shooting all around,” Andrada said. “I closed my eyes. We were going around in the desert. To me, I left it all to fate.”

Another survivor, an Algerian named Chabane, had an even grimmer tale of how the militants ruthlessly coerced a Briton into luring his compatriots out into the open.

Chabane, who worked in food services, said he bolted out a window and was hiding when he heard the militants speaking among themselves. At one point, he said, they captured a Briton.

“They threatened him until he called out in English to his friends, telling them, ‘Come out, come out. They’re not going to kill you. They’re looking for the Americans,’ ” he said. “A few minutes later they blew him away.”

Algerian officials said the heavily armed militants had planted mines and threatened to blow up the refinery and kill hostages or use them as shields to escape across the desert into Libya.

At one point, the militants reportedly offered to trade two American captives for two extremist figures jailed in the United States, including Sheik Omar Abdel Rahman, the blind Egyptian cleric convicted in 1995 of plotting to bomb landmarks in New York.

Saturday’s army raid killed 11 militants but not before they executed their final seven hostages.

By nightfall, troops had discovered 15 burned bodies and were securing the plant. However, an Algerian official said some of the bodies were charred beyond recognition, making it difficult to distinguish between the captors and the captured. Two were assumed to be hostages because they were handcuffed.

Nearly 700 Algerians and 107 foreigners had been freed or had escaped over the past two days.

A man identified as Brahim, an Algerian driver, told French media of his escape with a group including three foreigners.

“As bullets rang out non-stop, we cut holes in the metal fence with large clippers, and once through, we all started running,” he said. “There were about 50 of us plus the three foreigners. … I didn’t look back.”

However, when the final assault began Saturday at least 30 foreigners, including an estimated seven Americans, were still unaccounted for. They also included 14 Japanese, five Britons, two Malaysians and six employees of Statoil, a Norwegian company.

A Canadian who was among the employees at the site when the attack was launched on Wednesday is safe.

Some Western governments expressed frustration at not being informed of the Algerian authorities’ plans to storm the complex. One Algerian official defended the military assault, saying the militants were about to set off explosions.

He said the militants had already set fire to the plant’s control tower Friday night, creating an “immense fire” which was only extinguished through an all-night effort by soldiers and workers. They then attempted to blow up a pipeline.

“The authorities were afraid they were going to blow up the (natural gas) reserves,” said the senior official, who believed the militants had planned all along to destroy the plant.

French President François Hollande gave his backing to the tough tactics, saying that “there could be no negotiations (with terrorists).”

The militants were connected to a group known as Al Qaeda in the Islamic Maghreb, which arose from the Algerian civil war in the 1990s. The attackers reportedly included Libyans, Egyptians and at least one commander from Niger.

A White House official discounted that theory, saying the attack was planned far in advance of the French intervention in Mali.

Accounts by freed hostages and statements by Algerian officials indicated that the militants, some of whom wore fatigues and appeared to know their way around the compound, may have been assisted by contacts inside.

The refinery sits on a border rife with militants, traffickers and weapons, many of them looted and flowing in from an unstable Libya.

The suspected mastermind of the hostage crisis was Mokhtar Belmokhtar, a one-eyed Al Qaeda recruiter whose nicknames include Mr. Marlboro for his smuggling networks. He was believed to have been aiding the rebels in Mali.

The commander of the actual raid was a fighter from Niger called Abdul Rahman al-Nigeri, according to Mauritanian news agencies. Belmokhtar appears not to have joined the raid.

The natural gas refinery at In Amenas is operated by BP, Statoil and Sonatrach, the Algerian national oil company. Several of their employees are missing.

“We feel a deep and growing unease ... We fear that over the next few days we will receive bad news,” Statoil chief executive Helge Lund said “People we have spoken to describe unbelievable, horrible experiences.”