ALGIERS, Algeria (AP) -- The Islamist militants who attacked a natural gas plant in the Sahara wore Algerian army uniforms, memorized the layout of the vast complex and included two Canadians and a team of explosives experts ready to blow the place sky-high, Algeria's prime minister said Monday.
The operation also appeared to have help from the inside - a former driver at the plant, he said.
Algeria offered a grim toll in the attack, saying that 38 hostages and 29 militants died in four days of mayhem. The dead hostages included seven Japanese workers and three energy workers each from the U.S. and Britain.
Three of the attackers were captured and five foreign workers remain unaccounted for, the prime minister told reporters at a news conference in Algiers, the capital.
Monday's account offered the first Algerian government narrative of the four-day standoff, from the moment of the attempted bus hijacking to the moment when the attackers began to prepare to explode bombs across the massive gas plant that sprawled over 5 square kilometers ( 2 square miles).
All but one of the dead hostages - an Algerian driver - were foreigners. The prime minister said three attackers were captured but did not specify their nationalities or their conditions or say where they were being held.
He said the Islamists included a former driver at the complex who was from Niger and that the militants "knew the facility's layout by heart."
The militants had said during the standoff that their band included people from Canada, and hostages who had escaped recalled hearing at least one of the militants speaking English with a North American accent.
In addition to the Canadians, the militant cell included men from Egypt, Mali, Niger, Mauritania and Tunisia, as well as three Algerians.
"You may have heard the last words of the terrorist chief," Algerian Prime Minister Abdelmalek Sellal told reporters. "He gave the order for all the foreigners to be killed, so there was a mass execution, many hostages were killed by a bullet to the head."
A total of three Americans died in the attack and seven made it out safely, a U.S. official in Washington said, speaking on condition of anonymity because he was not authorized to speak publicly. Their bodies have been recovered, the official said.
The attack began early Wednesday with the attempted hijacking of two buses filled with workers outside the complex. Under assault from Algerian forces, the militants moved on the main complex, armed with missiles, mortars and bombs for their three explosives experts, Sellal said.
He praised the quick wits of a guard who set of an alarm that stopped the flow of gas and warned workers of an imminent attack.
"It was thanks to him that the factory was protected," he said.
Five foreigners remained unaccounted for, Sellal said. Japan's prime minister said Monday seven Japanese citizens were killed and three others are missing.
Sellal said the facility had 790 Algerian workers and 134 foreigners from 26 countries. The Algerians were freed early in the standoff - former hostages said the attackers immediately separated out the foreigners, forcing some to wear explosive belts.
The prime minister said the heavily armed militants came from Mali carrying a great deal of explosives and mined the facility. They had prepared the attack for two months.
Sellal justified the helicopter attack Thursday on vehicles filled with hostages out of the fear the kidnappers were attempting to escape.
The Algerian special forces assault on the refinery on Saturday that killed the last group of militants and hostages came after the kidnappers attempted to destroy the complex.
In a statement, the Masked Brigade, the group that claimed to have masterminded the takeover, has warned of more such attacks against any country backing France's military intervention in neighboring Mali, where the French are trying to stop an advance by Islamic extremists.
Sellal said the militants had expected to return to Mali with the foreign hostages. Seven French citizens taken hostage in recent years are thought to be held by al-Qaida linked groups in northern Mali.
"Their goal was to kidnap foreigners," Sellal said. "They wanted to flee to Mali with the foreigners but once they were surrounded they started killing the first hostages."
The operation was led by an Algerian, Amine Benchenab, who was known to security services and was killed during the assault, he added. Sellal said negotiating was essentially impossible.
"They led us into a real labyrinth, in negotiations that became unreasonable," he said.
Associated Press writer Bradley Klapper contributed to this report from Washington.