ALGIERS (Reuters) - The Islamist attack on the sprawling desert gas complex in southern Algeria that triggered one of the worst hostage crises in years was conceived in Mali and coordinated by a mystery Canadian named only as Chedad, the Algerian prime minister said.
Five days after about 40 jihadist fighters raided the facility not far from the Libyan border and Algeria responded with a full-on military operation to kill or capture them, a picture of what happened is emerging.
While some hostages escaped in the early stages of the crisis, hopes soon faded for dozens of others once the army decided to take on the raiders.
Workers from the United States, Britain, France, Japan, Romania, Norway and the Philippines were either dead or missing, with the overall death toll among hostages and militants put at 67 and potentially rising by up to five.
Those who escaped had harrowing tales to tell. One Briton recounted how the attackers had strapped Semtex plastic explosive around his neck, bound his hands and taped his mouth. Another man hid for more than a day and a half under his bed as jihadist fighters searched the workers' residential complex.
Algerian Prime Minister Abdelmalek Sellal said the plot had been hatched in war-ravaged Mali and the attackers had travelled through Niger and Libya before slipping into Algeria.
The jihadists were said to come from Egypt, Mauritania, Niger, Tunisia, Mali, Algeria and, in one case, from Canada. The Canadian, identified initially as Chedad, was coordinating the raiders, Sellal said.
The In Amenas gas plant probably felt impregnable to those who worked there - fenced in, hundreds of miles from anywhere and with the Algerian army patrolling its desert approaches.
That was a mirage. Libya, an ex-police state turned arms bazaar and now open for jihad, lies just 50 miles away.
At least some of the Islamist guerrillas who stormed in before dawn on Wednesday had driven along smugglers' tracks across the Libyan border, an Algerian security official told Reuters, citing evidence from mobile phones traced to the militants.
The militants arrived in nine Toyotas with Libyan plates and painted in the colours of Sonatrach, the Algerian oil and gas company that has a share in the plant, according to the Algerian daily El Khabar.
The ease with which they entered the fortified housing compound and nearby natural gas plant left Algerians in little doubt the gunmen had allies among people at the site.
"They had local cooperation, I'm sure, maybe from drivers or security guards, who helped the terrorists get into the base," was the immediate reaction of Anis Rahmani, editor of Algeria's Ennahar newspaper and a writer on security issues who said he was briefed by officials.
Sellal confirmed that a driver who had formerly worked at the plant had been supplying information to the raiders.
Locally hired workers who escaped told Reuters of seeing the gunmen moving around the facility with confidence, apparently familiar with its layout and well prepared.
The militants said they launched the raid to halt French military intervention in neighbouring Mali, which began earlier this month, however the link is not yet clear.
It is possible the attack would have happened anyway, or that the French military operation provided a trigger to carry out an attack based on preparations made earlier.
First word of trouble came crackling over a walkie-talkie to the communications room at In Amenas, where a 27-year-old radio operator called Azedine logged a contact with a bus driver who, at 5:45 a.m. (4.45 a.m. British Time), left to take some foreigners to the airstrip at the town of In Amenas, some 50 km (30 miles) away.
"Moments after the bus left, I heard shooting, a lot of shooting, and then nothing," Azedine told Reuters on Friday.
Two people, one British and one Algerian, were killed on two buses heading for the airport. The Briton was identified as a Gulf war veteran who had been in the French Foreign Legion and was working for a security company.
Sellal said the raiders planned to seize the foreign passengers, but came under fire from soldiers guarding them.
It is not clear whether that incident was part of the plan that secured the militants access to the compound. Almost immediately after the bus skirmish, they were inside, in at least three vehicles.
They shot an Algerian guard but he was able to raise the alarm before dying, Sellal said.
People who have worked at the site say there was normally an overnight curfew, leaving it unclear how the gunmen were able to get so close before being challenged. Their initial approach may have been well off the main roads.
Freed hostages spoke of frightened people staying in their offices or hiding in their dormitories.
Azedine saw a gunman put on the ID badge of a French supervisor who had been shot dead.
A French catering firm employee spent 40 hours cowering alone under his bed, terrified he would be killed.
Alexandre Berceaux said he had survived by staying in his room away from other foreigners, hidden behind a barricade of wooden planks and having Algerian colleagues sneak him food and water.
"I was completely isolated ... I was afraid. I could see myself already ending up in a wooden box," Berceaux said in a radio interview.
Rapidly the area was surrounded by heavily armed Algerian troops, with tanks, armoured vehicles and helicopter gunships from a nearby military base. Sellal said there had been an attempt to negotiate but it had collapsed over the hostage-takers' demands.
People who know the site, operated by Britain's BP and Statoil of Norway along with Algeria's Sonatrach, said a barracks housing several hundred soldiers lies along the three km (two miles) of road separating the accommodation compound from the industrial plant.
A former senior Algerian government official said guards appeared to have been caught napping: "They have all kinds of equipment, detailed surveillance, cameras," he said. "They were caught maybe at the right time, at five in the morning."
But he also acknowledged the militants may have had help among the local workforce: "Out of 700 Algerians, I am sure they will find a couple who will cooperate. It always happens."
Militant leaders like Taher Ben Cheneb, said by officials to have been one of the commanders of the operation and to have been killed on Thursday, have stoked resentment among southerners at the way foreigners and northerners dominate the better paid jobs in the oil fields.
Ben Cheneb, described as a high school maths teacher in his 50s, led the Movement of the Islamic Youth in the South. Security expert Rahmani said he joined forces for this operation with followers of Mokhtar Belmokhtar, a veteran of Afghan wars and a leading figure in Al Qaeda in the Islamic Maghreb (AQIM) who recently formed a new group named Mulathameen.
Belmokhtar, the overall commander but not present during the attack, claimed responsibility on behalf of al Qaeda for a raid he called a "blessed operation".
While Ben Cheneb's group appeared to have moved on In Amenas from a base inside Algeria, Rahmani said, another group led by Abu El Bara appeared to have come in from Libya.
The group's field commander was a veteran fighter from Niger called Abdul Rahman al-Nigeri, Mauritanian media reported. He led his men into the gas plant, where he is believed to have been killed, while Abu El Bara died at the residential complex.
Noting the one-eyed Belmokhtar's reputation as a cigarette smuggler as well as a holy warrior - locals call him "Mister Marlboro" - Rahmani added: "They use the same back roads as the smugglers. You need a perfect knowledge of the Sahara to do it.
Canadian diplomat Robert Fowler, who was captured by Belmokhtar in Niger in 2008 and released after four months, nicknamed him "Jack" so as to be able to discuss him privately with fellow captives. Belmokhtar in turn referred to his prisoners as apostates and infidels.
More than a decade after Algeria's civil war killed some 200,000 people, Islamist fighters roam the sandy wastes of Africa's biggest country, mixing smuggling and kidnapping for ransom with opposition to the political establishment that has ruled in Algiers since French colonists left half a century ago.
These groups have been energised by the return of heavily armed ethnic Tuaregs and others from Libya, where they fought as mercenaries for Muammar Gaddafi until his overthrow in 2011. The new Libyan authorities are struggling to control their own deep south and it provides a launchpad for raids across the frontier.
While security forces seek to impose control, the tracts of sand are vast, borders among the half dozen countries around the desert are unmarked, and the big money that can be made from illicit trade or kidnapping tourists and Western engineers can be used to buy favours from ill-paid officials.
Al Qaeda says it is fighting for a Muslim caliphate that transcends artificial borders in the Maghreb set by colonial powers.
Once inside the facility, militants, including bearded, ragged fighters and others in more urban dress, herded groups of Westerners together. Hundreds of Algerians were guarded more loosely. One Algerian worker told Reuters the gunmen said they were only interested in killing "Christians and infidels".
Algeria told Western governments, which voiced dismay at the storming of the facility on Thursday, that troops moved in only because guerrillas were trying to leave with hostages, hoping to reach Mali.
The captors loaded hostages into a convoy. Special forces backed by helicopters moved in around noon, some 30 hours after the plant was seized.
In what appears to have been the deadliest part of the siege, as described by the family of Irish survivor Stephen McFaul, government forces bombed the convoy, blasting apart four vehicles full of hostages. McFaul was in a fifth truck which crashed. He dashed for his life and escaped, and believes all those in the other vehicles were killed.
McFaul told how the attackers had turned him into a human bomb, strapping Semtex around his neck.
Another Briton, Garry Barlow, called his wife from within the site during the attack and said: "I'm sat here at my desk with Semtex strapped to my chest."
During Thursday, most of the hundreds of people at the site were able to flee, some of them Westerners posing as Algerians.
"We cut the wire with clippers and ran for it, all together, about 50 of us with the three foreigners," one man was quoted as saying by The Times.
By Friday night, it remained unclear how many of the gunmen and their hostages were still in the facility.
The operation at the larger, residential compound was over and troops were now surrounding the industrial site, where Nigeri and his men were reported to be holding a group of hostages.
But this left Western governments and intelligence officials, long used to difficult relations with Algeria which is proud of its sovereignty, desperate for hard facts about the fate of their nationals.
Western capitals seemed to be in the dark when the dramatic and bloody final assault came on Saturday morning.
Algerian soldiers shot dead 11 gunmen who had executed seven foreign hostages, according to the state news agency. The militants were then found to have booby-trapped the gas complex with explosives, which the army had to defuse.
The operation was over, authorities said, but mopping up went on for hours, with dozens more bodies found and many questions still to be answered.
(Additional reporting by Alex Lawler and Jessica Donati in London, Writing by Alastair Macdonald and; Giles Elgood, editing by Peter Millership)