Updated

An Al Qaeda-linked militant group who took control of a Algerian gas plant during a four-day-long siege that left 38 hostages dead, including three Americans, did it with help from the inside, Algeria's prime minister said Monday.

Abdelmalek Sellal, speaking to reporters at a news conference in Algiers, said the kidnappers came from Egypt, Canada, Mali, Niger, Mauritania and Tunisia.  He said the group, wearing Algerian army uniforms, included a former driver from Niger who worked at the facility and a team of explosives experts who had memorized the layout of the sprawling complex and were ready to blow the place sky-high. He added that two Canadians were among them.

Algeria detailed a grim toll from the attack, saying that 38 hostages and 29 militants died. Three of the attackers were captured and five foreign workers remained unaccounted for, Sellal told reporters at a news conference in Algiers, the capital.

He did not specify the nationalities of the captured militants, report their medical conditions or say where they were being held.

There has been no mention whether Mokhtar Belmoktar, the leader of the Al Qaeda-linked group behind the attack -- the Masked Brigade -- was among the captured or killed.

More On This...

In a statement, the Masked Brigade 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.

"We stress to our Muslim brothers the necessity to stay away from all the Western companies and complexes for their own safety, and especially the French ones," the statement said.

Belmoktar, a one-eyed Algerian in his 40s known in Pentagon circles as "MBM," just split off from Al Qaeda in the Islamic Maghreb, or AQIM, to start the Masked Brigade.

Over the past decade, AQIM has kidnapped dozens of foreigners, including diplomats, aid workers, field doctors and tourists.

Belmoktar prefers to trade his hostages for money, experts have said, and global intelligence unit Stratfor says he can get an estimated $3 million per European captive.

Seven Americans made it out of the gas plant safely during the siege, but the State Department on Monday confirmed three deaths: Victor Lynn Lovelady, Gordon Lee Rowan, and Frederick Buttaccio.

"As [President Obama] said, the blame for this tragedy rests with the terrorists who carried it out, and the United States condemns their actions in the strongest possible term," State Department spokeswoman Victoria Nuland said in a statement.

Monday's account from Sellal offered the first Algerian government narrative of the standoff, from the attempted bus hijacking early Wednesday to the moment when the attackers prepared to explode bombs across the gas plant, which spreads out over 2 square miles deep in the desert, 800 miles south of Algiers.

All but one of the dead hostages -- an Algerian driver -- were foreigners. The dead hostages included seven Japanese workers, six Filipinos, three energy workers each from Britain, two from Romania and one worker from France.

The final death toll was still unclear, since accounts from other governments appeared to indicate that more than five workers were still missing. It was also lower than the 81 estimated Sunday from Algerian reports of dead and missing.

The militants had said during the standoff that their group included Canadians, and hostages who had escaped recalled hearing at least one of the militants speaking English with a North American accent.

Officials in Canada could not immediately confirm whether two of the attackers were citizens.

"Canada condemns in the strongest possible terms this deplorable and cowardly act and all terrorist groups which seek to create and perpetuate insecurity," said Chrystiane Roy, a spokeswoman for the Department of Foreign Affairs.

"We are pursuing all appropriate channels to seek further information and are in close contact with Algerian authorities," she said in a statement.

The Algerian prime minister indicated that this operation was not -- as the Islamists had claimed -- an immediate reaction to France's recent military intervention against Islamists in neighboring Mali, since the captured militants said it took two months of planning. But he said the group did come from northern Mali, hundreds of miles away from the gas plant.

Hostages who escaped said the militants didn't just shoot their way into the facility.

"Four attackers stepped out of a car that had flashing lights on top of it," one of the former hostages, Liviu Floria, a 45-year-old mechanic from Romania, told The Associated Press.

The prime minister said "the last words of the terrorist chief" was to slaughter the hostages.

"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," he said.

Algeria has not reported any military deaths from four days of confronting the fighters.

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.

Floria, a former hostage, remembered the moment when the power was cut.

"I ran together with other expats and hid under the desks in my office, locking the door. Attackers went scanning the office facility, kicking the doors in. Luckily our door did not break and they went on to other offices," he said. "Locals were freed, the attackers made clear from the beginning that only foreigners were a target."

Floria ultimately escaped, but not before he heard the two gunshots that killed two wounded foreign hostages that he said he had tried to save.

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.

Sellal justified the Algerian military helicopter attack Thursday on vehicles filled with hostages and Islamists out of the fear that 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.

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 Qaeda linked groups in northern Mali.

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 not impossible.

"They led us into a real labyrinth, in negotiations that became unreasonable," he said.

Norway said five of its citizens from the plant were still unaccounted for, while Japan said three Japanese were still missing. Britain said three citizens and one resident were feared dead but not accounted for. Four Filipinos and two Malaysian plant workers were also missing, according to their governments.

The Associated Press contributed to this report.