Islamists are likely to be the principal beneficiaries of NATO's intervention.

“100 per cent sick and possessed of the devil,” Egypt's former President, Anwar al-Sadat, once said of the bizarre, almost unknown colonel who had begun to build a surreal dystopia to his country's west.

The world's media echoed that sentiment this month, as Muammar Qadhafi makes his last stand in Libya's southern desert. The North Atlantic Treaty Organisation (NATO) bombing campaign which forced him out of power, it is claimed, prevented epic bloodshed and laid the foundations for democracy.

Early in March, U.S. President Barack Obama claimed that if NATO waited “one more day, Benghazi could suffer a massacre that would have reverberated across the region and stained the conscience of the world.” Dennis Ross, a White House adviser on the Middle East, warned of the “real or imminent possibility that up to a 1,00,000 people could be massacred.”

Six months after those speeches, little evidence has emerged to show that such a massacre was in fact being contemplated: no large-scale killings appear to have taken place in cities which the regime held on reoccupied, though both sides had engaged in killings and torture. Had 1,00,000 in fact been massacred, Libya would have seen one of the largest genocides since the partition of India — rivalled in scale only by the massacre of South Korean communists by U.S.-backed forces in 1950.

This we do know: between 30,000 and 50,000 are reported to have died in a war meant to stop a massacre.

Even worse, the end of the war in Libya is more than likely to be followed by a no less murderous peace.

Libya's Islamist rebirth: “Air Cargo,” was how MI6 officer Mark Allen called him, in a secret letter to Libya's Foreign Minister, written on Christmas Day in 2003. Last month, six years after the CIA and MI6 put him into a grim warehouse in Tripoli called the Abu Salim prison, the “Air Cargo” reappeared at the head of the forces which stormed Tripoli. Abdelhakim Belhadj's story illustrates the Islamist rebirth in Libya — and helps to understand just why the euphoria over Mr. Qadhafi's defeat might prove ill-founded.

Born in 1966, Mr. Belhadj graduated with a degree in civil engineering, before leaving for Afghanistan in 1988 to fight in the jihad against the Soviet Union. He returned home in 1990 to help found the Libyan Islamic Fighting Group (LIFG), a jihadist group determined to overthrow the country's “Pharoah.” It was generously aided in that enterprise, a former MI6 officer David Shayler alleged, by Britain's intelligence services.

From his web page on Minbar al-Tawhid, the leading Middle Eastern jihadist site, we know something of Mr. Belhadj's world view: the LIFG, he proclaimed, opposed democracy as a mater of religious doctrine, as those who believe in the glory of Islam could be achieved without a jihad.

Ideas like these had begun to gain ground in Libya in the mid-1980s, as a combination of falling oil prices and Saudi Arabian support for neo-fundamentalist Islam started to undermine his regime's foundations.

Until the 1969 coup which brought Mr. Qadhafi to power, Libya was ruled by the descendants of Muhammad Ibn al-Sanusi — a religious revivalist who gave clerics a key role in his monarchical apparatus. Mr. Qadhafi's regime soon sidelined the mullahs, seizing control of mosques and nationalising religious endowments. He even began to propagate his own, eccentric version of Islam.

From 1990, following the end of the Afghan jihad, the pressures grew. Libyan jihad-veterans began arriving home to a country hard hit by unemployment and inflation. In 1993, the Libyan army had to put down a mutiny which left hundreds dead; the following year, jihadists successfully stormed a prison; in 1995, dozens more died in fierce fighting around Benghazi; in 1996, a string of attacks compelled the regime to launch air strikes against the LIFG's mountain bases.

The LIFG was routed in combat, but its leadership found succour overseas. Much of its leadership shifted to London, often after the rejection of its claims on security grounds by continental European governments, joining hands with MI6 to wage war against Mr. Qadhafi. Elements of the Libyan jihadist movement also joined with the al-Qaeda in Sudan. Nazih Abdul-Hamed Nabih al-Ruqai'i, one of the architects of the 1998 bombings in Dar-es-Salaam and Nairobi, was a LIFG veteran; so too is Abu Yahya al-Libi, among the al-Qaeda's top ideologues.

In 2007, Ayman al-Zawahiri, now the al-Qaeda's chief, announced that the LIFG had merged with the al-Qaeda. In his recorded message, he hailed the imprisoned Mr. Belhadj as the “emir of the mujahideen.”

Belhadj was, in fact, then engaged in a secret dialogue with Saif al-Islam Qadhafi, Mr. Qadhafi's London-educated son, who was attempting to bring about a rapprochement with the Islamists.

It paid off. In 2009, three incarcerated Libyan Islamists — Khalid Sharif, Sami al-Sa'idi and Belhadj — published a manifesto called Corrective Studies in the Concepts of Jihad. Endorsed by both Libyan authorities and the influential Islamist ideologue Youssef al-Qaradhawi, the book argued that a jihad against Muslim rulers was illegitimate. Instead, Islamists fighting for the faith ought to focus on external “conspiracies by its enemies, the Jews and Christians.”

The deal done, a clean-shaven Belhadj was reintroduced to the world at a press conference chaired by Saif al-Islam Qadhafi in March 2010, nodding in agreement as the dictator's son described the new friendship between the regime and its Islamist enemies. More prisoner releases followed — the last, ironically enough, just two days before fighting broke out in Benghazi.

The “anti-state”: Islamists now have exceptional opportunities in Libya, evocatively described by one scholar as an “anti-state”; a system where power is derived from oil sales, not through taxation; through tribal patronage rather than modern institutions. Indeed, it is startling that NATO took so long to dislodge Mr. Qadhafi. His ill-trained armed forces were only 91,000 strong at their peak — about a third of the number needed, the expert Anthony Cordesman has estimated, to operate Libya's gargantuan equipment stockpiles.

For centuries, Libya's Ottomon rulers left the country disunited. Italian colonialism brought together Tripolitania in the west, Cyrenaica in the east, and arid central Fezzan, through a ferocious war that ran from 1922 to 1935, and involved the liberal use of poison gas against tribesmen.

The Eastern tribes, who played a key role in the struggle against the Italians, won out in the negotiations that led to Libya's independence. King Idris al-Senussi, their figurehead, received the throne as a Christmas Eve gift in 1951.

Mr. Qadhafi's coup placed his western Qadhafdha tribe and its allies at the top of the pile — but he did not aspire to dismantle tribalism. His manifesto, The Green Book, applauded the tribe as a form of “natural social protection.” The nation state, with its institutions, was an “artificial political, economic and sometimes military system which has no link to human values.”

The army became the stage on which tribal tensions were played out. In 1993, for example, Abdel Salam Jalloud — a trusted lieutenant who had, in 1970, been dispatched to offer China £75 million for a nuclear weapon — attempted to seize power. Mr. Jalloud's Magariha tribe backed him, along with the Warfalla and al-Zintan — much the same coalition that brought down Mr. Qadhafi.

Each of those tribes, and their ethnic Berber allies, are now asserting their right to power — while the western tribal coalitions which backed Mr. Qadhafi are preparing to resist their claims. In the absence of mass political parties or a functional state to mediate this struggle, a protracted insurgency seems possible.

Islamist military commanders Abdel Karim al-Hasidi and Ibrahim Ahmed bin-Qumu, held until not long ago in Guantánamo, alone have the ideological discipline and military resources needed to mediate this looming power struggle. NATO intervention has thus given Libya's Islamists a fighting chance to win what they failed to secure on the battlefield: state power.

The long-standing links of Libya's Islamists with the international jihadist movement mean their triumph will have regional implications. Thousands of portable SA7 anti-aircraft missiles have been looted from Libya's arsenals. Idriss Itno, Chad's President, has said, “Al-Qaeda took advantage of the pillaging of arsenals in the rebel zone to acquire arms, including surface-to-air missiles.” Moshe Ya'alon, Israel's Vice-President, has claimed that Islamist groups have been buying weapons from Libyan smugglers.

Earlier this year, the al-Qaeda's al-Libi released a videotape railing against Mr. Qadhafi — “the false prophet of our times, the evil liar, curser of the Prophet Muhammad.” Mr. Qadhafi, he claimed, “turned his people into guinea pigs for his putrid ideas, his stinking nonsense, his reckless policies, and his stupid, idiotic notions.”

Few words were present in that speech which western commentators and politicians have not since deployed — an irony which needs little elaboration.

“War is the father of all things,” wrote Heraclitus, “the king of all: some it has shown as gods, some as men; some it has made slaves, some free.” Libya's new political leadership may well, as western optimists claim, marginalise the Islamists and build a democratic future — but the ancient Greek philosopher's words should compel consideration of not just the costs of defeat, but also victory.

This story was corrected for a factual error.