Editor’s note: This article was originally published by Al Monitor.

David Cameron’s visit to Algiers last week, the first ever by a British Prime Minister, underscores Algeria’s growing importance in the war against al-Qaeda. But it is an extraordinarily complex ally in the war. The generals who run Algeria, the Arab world’s largest remaining police state, were surprised and embarrassed by the al-Qaeda attack on the Amenas gas facility in January. Their worry now is that the attack will raise questions about their one strong competency, providing stability and fighting terror. They are the West’s ally but a difficult and very suspicious partner.

Cameron and his hosts agreed to develop a strategic partnership to fight terrorism, and especially al-Qaeda in the Islamic Maghreb, now that the French have driven it out of Mali’s cities. In practice, this will mean closer ties with Algeria’s Departement du Renseignement et de la Securite, DRS, one of the world’s most feared intelligence services.

Algeria is geographically the largest country in Africa and in the Arab world. President Abdelaziz Bouteflika, 79, has run the country since his election in 1999. He ended a brutal and bloody civil war that began after an army coup in 1991 that overturned free elections that had been won by an Islamist party. In the violence that followed an estimated 200,000 died. In 1994, Algerian terrorists hijacked a jet bound for Paris with the intent of smashing it into the Eiffel tower, the plot that inspired 9/11. The army reacted with brute force. Algiers in the mid 1990s was as dangerous a city as any in the world. Bouteflika offered amnesty and initiated reforms to win over an exhausted nation. Now in his third term, he was reelected in 2009 with 90% of the vote in what critics charge was massive vote fraud.

Algeria shares all the same demographic time bombs as its neighbors to the east, Tunisia, Libya and Egypt, which have had revolutions against their police states in the last two years. Seventy per cent of Algeria’s 35 million people are under the age of 30, 30% are under the age of 15 and thus have no memory of the 1990s nightmare. Unemployment among young men has been a major problem since the 1970s despite vigorous efforts to reduce it. While women can participate in the work force and are well educated by regional standards, they too are often unemployed or under-employed. University graduates often find they can not get jobs commensurate with their education skills. Groups of angry young men can be seen every day in every Algerian city.

The oil and natural gas economy provides only a small number of jobs. Tourism could produce many more but the country is not tourist-friendly despite beaches, wine and Roman ruins. Its reputation as a violent and dangerous place discourages Europeans looking for sun. The regime fears opening the country up to outsiders.

While Bouteflika is the public face of the government, real power still resides with the generals. They avoid the public limelight and are known in Algiers as “le pouvoir,” the power behind the scenes. In the shadowy world of “le pouvoir,” the most powerful man is probably the head of the secret police or mukhabarat. The head of Algerian intelligence, the DRS, Mohammad Mediene, has a long track record of eradicating terrorist groups using extreme methods. KGB-trained and rarely photographed, the 73-year-old Mediene has run Algerian intelligence since 1990 and is known for his professionalism and determination. He is also known by his nickname, ‘the god of Algiers,’ because his power is so pervasive and unaccountable. Born in 1939, he served in the French colonial army before defecting to the nationalist revolt when it began in the 1950s. Mediene is now the longest serving head of intelligence in the world. And probably the most ruthless.

His deputy, Bashir Tartag, commanded the actual assault on the terrorists in the desert facility. His nickname is “le bombardier” and he is also known for his support for the so called eradicationist school of counter-terrorism. But the DRS is also known for its tactic of infiltrating terrorist groups, creating “false flag” terrorists and trying to control them. Rumors have associated the DRS in the past with the Malian warlord Iyad Ag Ghali, head of Ansar al Dine AQIM’s ally in Mali, and even with Mukhtar Belmukhtar, the al-Qaeda terrorist who engineered the attack on the natural gas plant. The Algerians hope is that they can influence these groups to stay away from Algerian targets. The tactic originates with KGB and was developed by the DRS in the 1990s. It had success in dividing the jihadists then. This year is failed disastrously in Mali when the terrorists took events into their hands.

Algeria has the largest army in Africa t over 150,000 strong, a defense budget of more than $10 billion annually and extensive spy networks across the Sahara. Algerians are fiercely nationalistic after more than 1 million Algerians died in the war for independence from France. It remains especially sensitive and nervous about French actions. Algiers opposed France and NATO’s role in Libya which it blames for starting the Mali mess. But the Algerians did allow French fighter jets to fly over Algerian territory to bomb al-Qaeda in the Islamic Maghreb targets in Mali.

Ironically, the attack probably will push Algiers off the fence about the war in Mali. The generals who run Algeria initially were reluctant to push AQIM out of Mali fearing it would only come back north in to Algeria. Now they have no choice. With a GDP of $260 billion, a large Russian-equipped army and a ruthless intelligence service, it can do more to fight AQIM than any other African country. Thus Cameron’s visit.

America has had a difficult and troubled relationship with Algeria for centuries. We fought our first foreign war in Algiers to defeat the Barbary pirates. American GIs liberated it from the Vichy French and Nazis in 1942 and John F. Kennedy helped pressure Paris into giving up their colony in 1962, but for most of cold war, Algeria was a Soviet ally. It brokered the hostage release from Iran in 1981 because it had revolutionary credentials with Ayatollah Khomeini.

President George H. W. Bush gave the generals tacit support for their coup in 1991 after the fact. Bill Clinton started a dialogue with Bouteflika in 1999 when they met at the funeral for Moroccan King Hassan. President George W. Bush hosted Bouteflika in the White House to gain Algerian support after 9/11 against al-Qaeda. Obama has sent his counter-terror czar John Brennan and Secretary Hillary Clinton to Algiers, but the relationship has always been tense and marked by suspicion. Brennan will inherit the counter-terrorist liaison portfolio when he is confirmed as the next Director of Central Intelligence.