ALGIERS Algeria's decision to give refuge to members of Muammar Gaddafi's family is rooted in its leaders' deep fears that the revolution in neighbouring Libya will revive the Islamist violence it has spent years battling.
By letting Gaddafi's wife, two sons, and daughter flee into its territory, Algeria risks diplomatic isolation, but its government has shown it is unafraid of swimming against the tide of international opinion where its interests are at stake.
Libya's interim ruling council described Algeria's decision as "an act of aggression" -- the latest salvo in an increasingly hostile relationship between Algeria and the rebels who have overthrown Muammar Gaddafi.
Energy exporter Algeria is the only country along Africa's northern coast which has not recognised the interim National Transitional Council, and for months it has faced accusations -- angrily denied -- that it was backing Gaddafi in the civil war.
That hostility is based primarily on one thing: Algeria had little affection for Gaddafi's rule, but it does not trust the National Transitional Council to keep a lid on al Qaeda's north African wing.
"The Islamists represent a critical component of the (Libyan) rebels -- but not the militant Islamists," Fawaz Gerges, a professor of Middle Eastern politics at the London School of Economics, told BBC Television.
"Many of the former jihadi members say they have repented, now they believe in open society. But the reality is that even the Americans and the Europeans are concerned about the presence of a small segment of Islamists among the rebels," he said.
"Algeria, with thousands of kilometres of border with Libya, must handle this issue with care and considers Algeria's security as a top priority," said Abdelhamid si Afif, chairman of the foreign affairs committee in Algeria's parliament and a senior member of the ruling party.
Gaddafi's entourage probably decided to seek safe haven in Algeria precisely because of the hostility between the Algerian government and the new Libyan rulers. Other neighbours, such as Tunisia and Egypt, are friendlier to the anti-Gaddafi forces.
"This is the natural destination for Gaddafi," Gerges told the BBC.
Algeria's own experience makes it wary about Islamist violence. A conflict between the government and Islamist militants, which reached its peak in the 1990s, killed an estimated 200,000 people.
The violence has subsided in the past few years through a combination of tough security measures and a programme of reconciliation with Islamists who agree to lay down their arms.
Algeria's security weak spot is the huge expanse of desert and the porous borders in its south. Here, it has relied heavily on cooperation with neighbours, including Libya under Gaddafi.
The past few weeks have seen a resurgence of high-profile suicide attacks in Algeria. Last week 18 people were killed when two bombers targeted a barracks in western Algeria. A bomb attack on a police headquarters in July killed two people, and one on another police target injured 29 people this month.
Algerian security officials believe this could be the result of al Qaeda's local branch exploiting chaos in Libya to get their hands on weapons, and in particular plastic explosives.
Security experts say Gaddafi acquired stocks of the material from Czechoslovakia during the Cold War, and these could now be vulnerable.
A senior Algerian government source told Reuters last week: "We want to be certain that the new rulers in Libya are involved in the fight against al Qaeda in our region -- this is key for good relations."
Algeria may have angered Libya's interim rulers by allowing in Gaddafi's family, but it is not contravening international law or United Nations sanctions. None of the group now in Algeria is wanted by the International Criminal Court.
"Algeria is a sovereign state and it receives who it wants," said Abdelwahahab Djakoun, editor of the pro-government daily La Nouvelle Republique.
"The people it has received are not involved in the conflict. Algeria has also informed (UN Secretary-General) Ban Ki-moon as well as the Libyans," he told Reuters.
Saad Djebbar, a UK-based Algerian lawyer who once advised Gaddafi's government, said Algeria would be justified in allowing even Muammar Gaddafi himself to enter the country if that brought a swifter end to the fighting in Libya.
"If you allow Gaddafi to continue to be where he is, that means he could carry on his acts of sabotage or violent operations ... to undermine security," Djebbar said.
"But if he was in Algeria, the Algerians could control him ... (prevent him) from him being active in the Libyan territory any more."
Algeria will not be too troubled by adverse diplomatic reaction in the West because it has been in that position before.
It was snubbed by the United States and Europe for years over its conflict with the Islamists, until the West made common cause with its fight against Islamist militants after the Sept. 11, 2001 attacks on U.S. cities.
"Algeria has a kind of 'third-worldist' complex that makes it a unique country in the way it pursues policy ... and defines its interests," said Larbi Sadiki, a senior lecturer in Middle East politics at Britain's Exeter University.
"In a way they can do that as it is one of the least dependent countries on foreign aid in the region."
Nevertheless, Algeria's stance on Libya is risky.
Its rulers would prefer not to go back to the international isolation of the 1990s, whose removal President Abdelaziz Bouteflika sees as one of his biggest achievements.
There is also a danger its Libya policy could inflame public opinion at home.
Parts of Algeria's feisty press have already criticised the government for not embracing the anti-Gaddafi movement in Libya. Ordinary Algerians have followed the conflict closely, and share the general sense in the Arab world that Gaddafi is a despot.
"If (Muammar) Gaddafi's presence is announced in Algeria, maybe riots will take place. Maybe people will really use it as an excuse to protest," said Djebbar, the Algerian lawyer.
"I would argue the Algerian regime is making a major blunder, miscalculating monstrously. The Algerian regime itself is not immune from the revolutionary momentum taking place in the Arab world," said the LSE's Gerges.
Other analysts say that is overstated. After the violence they experienced in the 1990s, few Algerians now have an appetite for an "Arab Spring" uprising of their own.
The most likely outcome is that Bouteflika -- who for most of his career was a well-regarded diplomat -- will find a way out, possibly by sending Gaddafi's family into exile in a third country, or handing them over to Libya.
"I do think he will end up making a decision that he thinks will not adversely affect Algeria's longer-term strategic position," said David Hartwell, senior Middle East and North Africa analyst at IHS Jane's.
"Bouteflika is an extremely canny politician ," he said.
(Writing by Christian Lowe; Editing by Tim Pearce)