As the so-called Islamic State demolishes nation states set up by the Europeans almost a century ago, IS’s obscene savagery seems to epitomise the violence that many believe to be inherent in religion in general and Islam in particular. It also suggests that the neoconservative ideology that inspired the Iraq war was delusory, since it assumed that the liberal nation state was an inevitable outcome of modernity and that, once Saddam’s dictatorship had gone, Iraq could not fail to become a western-style democracy. Instead, IS, which was born in the Iraq war and is intent on restoring the premodern autocracy of the caliphate, seems to be reverting to barbarism. On 16 November, the militants released a video showing that they had beheaded a fifth western hostage, the American aid worker Peter Kassig, as well as several captured Syrian soldiers. Some will see the group’s ferocious irredentism as proof of Islam’s chronic inability to embrace modern values.

Yet although IS is certainly an Islamic movement, it is neither typical nor mired in the distant past, because its roots are in Wahhabism, a form of Islam practised in Saudi Arabia that developed only in the 18th century. In July 2013, the European Parliament identified Wahhabism as the main source of global terrorism, and yet the Grand Mufti of Saudi Arabia, condemning IS in the strongest terms, has insisted that “the ideas of extremism, radicalism and terrorism do not belong to Islam in any way”. Other members of the Saudi ruling class, however, look more kindly on the movement, applauding its staunch opposition to Shiaism and for its Salafi piety, its adherence to the original practices of Islam. This inconsistency is a salutary reminder of the impossibility of making accurate generalisations about any religious tradition. In its short history, Wahhabism has developed at least two distinct forms, each of which has a wholly different take on violence.

During the 18th century, revivalist movements sprang up in many parts of the Islamic world as the Muslim imperial powers began to lose control of peripheral territories. In the west at this time, we were beginning to separate church from state, but this secular ideal was a radical innovation: as revolutionary as the commercial economy that Europe was concurrently devising. No other culture regarded religion as a purely private activity, separate from such worldly pursuits as politics, so for Muslims the political fragmentation of their society was also a religious problem. Because the Quran had given them a sacred mission – to build a just economy in which everybody was treated with equity and respect – the political well-being of the umma (“community”) was always a matter of sacred import. If the poor were oppressed, the vulnerable exploited or state institutions corrupt, Muslims were obliged to make every effort to put society back on track.

So the 18th-century reformers were convinced that if Muslims were to regain lost power and prestige, they must return to the fundamentals of their faith, ensuring that God – rather than materialism or worldly ambition – dominated the political order. There was nothing militant about this “fundamentalism”; rather, it was a grass-roots attempt to reorient society and did not involve jihad. One of the most influential of these revivalists was Muhammad Ibn Abd al-Wahhab (1703-91), a learned scholar of Najd in central Arabia, whose teachings still inspire Muslim reformers and extremists today. He was especially concerned about the popular cult of saints and the idolatrous rituals at their tombs, which, he believed, attributed divinity to mere mortals. He insisted that every single man and woman should concentrate instead on the study of the Quran and the “traditions” (hadith) about the customary practice (Sunnah) of the Prophet and his companions. Like Luther, Ibn Abd al-Wahhab wanted to return to the earliest teachings of his faith and eject all later medieval accretions. He therefore opposed Sufism and Shiaism as heretical innovations (bidah), and he urged all Muslims to reject the learned exegesis developed over the centuries by the ulema (“scholars”) and interpret the texts for themselves.

This naturally incensed the clergy and threatened local rulers, who believed that interfering with these popular devotions would cause social unrest. Eventually, however, Ibn Abd al-Wahhab found a patron in Muhammad Ibn Saud, a chieftain of Najd who adopted his ideas. But tension soon developed between the two because Ibn Abd al-Wahhab refused to endorse Ibn Saud’s military campaigns for plunder and territory, insisting that jihad could not be waged for personal profit but was permissible only when the umma was attacked militarily. He also forbade the Arab custom of killing prisoners of war, the deliberate destruction of property and the slaughter of civilians, including women and children. Nor did he ever claim that those who fell in battle were martyrs who would be rewarded with a high place in heaven, because a desire for such self-aggrandisement was incompatible with jihad. Two forms of Wahhabism were emerging: where Ibn Saud was happy to enforce Wahhabi Islam with the sword to enhance his political position, Ibn Abd al-Wahhab insisted that education, study and debate were the only legitimate means of spreading the one true faith.

Yet although scripture was so central to Ibn Abd al-Wahhab’s ideology, by insisting that his version of Islam alone had validity, he had distorted the Quranic message. The Quran firmly stated that “There must be no coercion in matters of faith” (2:256), ruled that Muslims must believe in the revelations of all the great prophets (3:84) and that religious pluralism was God’s will (5:48). Muslims had, therefore, been traditionally wary of takfir, the practice of declaring a fellow Muslim to be an unbeliever (kafir). Hitherto Sufism, which had developed an outstanding appreciation of other faith traditions, had been the most popular form of Islam and had played an important role in both social and religious life. “Do not praise your own faith so exclusively that you disbelieve all the rest,” urged the great mystic Ibn al-Arabi (d.1240). “God the omniscient and omnipresent cannot be confined to any one creed.” It was common for a Sufi to claim that he was a neither a Jew nor a Christian, nor even a Muslim, because once you glimpsed the divine, you left these man-made distinctions behind.

Despite his rejection of other forms of Islam, Ibn Abd al-Wahhab himself refrained from takfir, arguing that God alone could read the heart, but after his death Wahhabis cast this inhibition aside and the generous pluralism of Sufism became increasingly suspect in the Muslim world.

After his death, too, Wahhabism became more violent, an instrument of state terror. As he sought to establish an independent kingdom, Abd al-Aziz Ibn Muhammad, Ibn Saud’s son and successor, used takfir to justify the wholesale slaughter of resistant populations. In 1801, his army sacked the holy Shia city of Karbala in what is now Iraq, plundered the tomb of Imam Husain, and slaughtered thousands of Shias, including women and children; in 1803, in fear and panic, the holy city of Mecca surrendered to the Saudi leader.

Eventually, in 1815, the Ottomans despatched Muhammad Ali Pasha, governor of Egypt, to crush the Wahhabi forces and destroy their capital. But Wahhabism became a political force once again during the First World War when the Saudi chieftain – another Abd al-Aziz – made a new push for statehood and began to carve out a large kingdom for himself in the Middle East with his devout Bedouin army, known as the Ikhwan, the “Brotherhood”.

In the Ikhwan we see the roots of IS. To break up the tribes and wean them from the nomadic life, which was deemed incompatible with Islam, the Wahhabi clergy had settled the Bedouin in oases, where they learned farming and the crafts of sedentary life and were indoctrinated in Wahhabi Islam. Once they exchanged the time-honoured ghazu raid, which typically resulted in the plunder of livestock, for the jihad, these Bedouin fighters became more violent and extreme, covering their faces when they encountered Europeans and non-Saudi Arabs and fighting with lances and swords because they disdained weaponry not used by the Prophet. In the old ghazu raids, the Bedouin had always kept casualties to a minimum and did not attack non-combatants. Now the Ikhwan routinely massacred “apostate” unarmed villagers in their thousands, thought nothing of slaughtering women and children, and routinely slit the throats of all male captives.

In 1915, Abd al-Aziz planned to conquer the Hijaz (an area in the west of present-day Saudi Arabia that includes the cities of Mecca and Medina), the Persian Gulf to the east of Najd, and the land that is now Syria and Jordan in the north, but during the 1920s he tempered his ambitions in order to acquire diplomatic standing as a nation state with Britain and the United States. The Ikhwan, however, continued to raid the British protectorates of Iraq, Transjordan and Kuwait, insisting that no limits could be placed on jihad. Regarding all modernisation as bidah, the Ikhwan also attacked Abd al-Aziz for permitting telephones, cars, the telegraph, music and smoking – indeed, anything unknown in Muhammad’s time – until finally Abd al-Aziz quashed their rebellion in 1930.

After the defeat of the Ikhwan, the official Wahhabism of the Saudi kingdom abandoned militant jihad and became a religiously conservative movement, similar to the original movement in the time of Ibn Abd al-Wahhab, except that takfir was now an accepted practice and, indeed, essential to the Wahhabi faith. Henceforth there would always be tension between the ruling Saudi establishment and more radical Wahhabis. The Ikhwan spirit and its dream of territorial expansion did not die, but gained new ground in the 1970s, when the kingdom became central to western foreign policy in the region. Washington welcomed the Saudis’ opposition to Nasserism (the pan-Arab socialist ideology of Egypt’s second president, Gamal Abdel Nasser) and to Soviet influence. After the Iranian Revolution, it gave tacit support to the Saudis’ project of countering Shia radicalism by Wahhabising the entire Muslim world.

The soaring oil price created by the 1973 embargo – when Arab petroleum producers cut off supplies to the US to protest against the Americans’ military support for Israel – gave the kingdom all the petrodollars it needed to export its idiosyncratic form of Islam. The old military jihad to spread the faith was now replaced by a cultural offensive. The Saudi-based Muslim World League opened offices in every region inhabited by Muslims, and the Saudi ministry of religion printed and distributed Wahhabi translations of the Quran, Wahhabi doctrinal texts and the writings of modern thinkers whom the Saudis found congenial, such as Sayyids Abul-A’la Maududi and Qutb, to Muslim communities throughout the Middle East, Africa, Indonesia, the United States and Europe. In all these places, they funded the building of Saudi-style mosques with Wahhabi preachers and established madrasas that provided free education for the poor, with, of course, a Wahhabi curriculum. At the same time, young men from the poorer Muslim countries, such as Egypt and Pakistan, who had felt compelled to find work in the Gulf to support their families, associated their relative affluence with Wahhabism and brought this faith back home with them, living in new neighbourhoods with Saudi mosques and shopping malls that segregated the sexes. The Saudis demanded religious conformity in return for their munificence, so Wahhabi rejection of all other forms of Islam as well as other faiths would reach as deeply into Bradford, England, and Buffalo, New York, as into Pakistan, Jordan or Syria: everywhere gravely undermining Islam’s traditional pluralism.

A whole generation of Muslims, therefore, has grown up with a maverick form of Islam that has given them a negative view of other faiths and an intolerantly sectarian understanding of their own. While not extremist per se, this is an outlook in which radicalism can develop. In the past, the learned exegesis of the ulema, which Wahhabis rejected, had held extremist interpretations of scripture in check; but now unqualified freelancers such as Osama Bin Laden were free to develop highly unorthodox readings of the Quran. To prevent the spread of radicalism, the Saudis tried to deflect their young from the internal problems of the kingdom during the 1980s by encouraging a pan-Islamist sentiment of which the Wahhabi ulema did not approve.

Where Islamists in such countries as Egypt fought tyranny and corruption at home, Saudi Islamists focused on the humiliation and oppression of Muslims worldwide. Television brought images of Muslim suffering in Palestine or Lebanon into comfortable Saudi homes. The gov­ernment also encouraged young men to join the steady stream of recruits from the Arab world who were joining the Afghans’ jihad against the Soviet Union. The response of these militants may throw light on the motivation of those joining the jihad in Syria and Iraq today.

A survey of those Saudi men who volunteered for Afghanistan and who later fought in Bosnia and Chechnya or trained in al-Qaeda camps has found that most were motivated not by hatred of the west but by the desire to help their Muslim brothers and sisters – in rather the same way as men from all over Europe left home in 1938 to fight the Fascists in Spain, and as Jews from all over the diaspora hastened to Israel at the beginning of the Six Day War in 1967. The welfare of the umma had always been a spiritual as well as a political concern in Islam, so the desperate plight of their fellow Muslims cut to the core of their religious identity. This pan-Islamist emphasis was also central to Bin Laden’s propaganda, and the martyr-videos of the Saudis who took part in the 9/11 atrocity show that they were influenced less by Wahhabism than by the pain and humiliation of the umma as a whole.

Like the Ikhwan, IS represents a rebellion against the official Wahhabism of modern Saudi Arabia. Its swords, covered faces and cut-throat executions all recall the original Brotherhood. But it is unlikely that the IS hordes consist entirely of diehard jihadists. A substantial number are probably secularists who resent the status quo in Iraq: Ba’athists from Saddam Hussein’s regime and former soldiers of his disbanded army. This would explain IS’s strong performance against professional military forces. In all likelihood, few of the young recruits are motivated either by Wahhabism or by more traditional Muslim ideals. In 2008, MI5’s behavioural science unit noted that, “far from being religious zealots, a large number of those involved in terrorism do not practise their faith regularly. Many lack religious literacy and could . . . be regarded as religious novices.” A significant proportion of those convicted of terrorism offences since the 9/11 attacks have been non-observant, or are self-taught, or, like the gunman in the recent attack on the Canadian parliament, are converts to Islam. They may claim to be acting in the name of Islam, but when an untalented beginner tells us that he is playing a Beethoven sonata, we hear only cacophony. Two wannabe jihadists who set out from Birmingham for Syria last May had ordered Islam for Dummies from Amazon.

It would be a mistake to see IS as a throwback; it is, as the British philosopher John Gray has argued, a thoroughly modern movement that has become an efficient, self-financing business with assets estimated at $2bn. Its looting, theft of gold bullion from banks, kidnapping, siphoning of oil in the conquered territories and extortion have made it the wealthiest jihadist group in the world. There is nothing random or irrational about IS violence. The execution videos are carefully and strategically planned to inspire terror, deter dissent and sow chaos in the greater population.

Mass killing is a thoroughly modern phenomenon. During the French Revolution, which led to the emergence of the first secular state in Europe, the Jacobins publicly beheaded about 17,000 men, women and children. In the First World War, the Young Turks slaughtered over a million Armenians, including women, children and the elderly, to create a pure Turkic nation. The Soviet Bolsheviks, the Khmer Rouge and the Red Guard all used systematic terrorism to purge humanity of corruption. Similarly, IS uses violence to achieve a single, limited and clearly defined objective that would be impossible without such slaughter. As such, it is another expression of the dark side of modernity.

In 1922, as Mustafa Kemal Atatürk rose to power, he completed the Young Turks’ racial purge by forcibly deporting all Greek-speaking Christians from Turkey; in 1925 he declared null and void the caliphate that IS has vowed to reinstate. The caliphate had long been a dead letter politically, but because it symbolised the unity of the umma and its link with the Prophet, Sunni Muslims mourned its loss as a spiritual and cultural trauma. Yet IS’s projected caliphate has no support among ulema internationally and is derided throughout the Muslim world. That said, the limitations of the nation state are becoming increasingly apparent in our world; this is especially true in the Middle East, which has no tradition of nationalism, and where the frontiers drawn by invaders were so arbitrary that it was well nigh impossible to create a truly national spirit. Here, too, IS is not simply harking back to a bygone age but is, however eccentrically, enunciating a modern concern.

The liberal-democratic nation state developed in Europe in part to serve the Industrial Revolution, which made the ideals of the Enlightenment no longer noble aspirations but practical necessities. It is not ideal: its Achilles heel has always been an inability to tolerate ethnic minorities – a failing responsible for some of the worst atrocities of the 20th century. In other parts of the world where modernisation has developed differently, other polities may be more appropriate. So the liberal state is not an inevitable consequence of modernity; the attempt to produce democracy in Iraq using the colo­nial methods of invasion, subjugation and occupation could only result in an unnatural birth – and so IS emerged from the resulting mayhem.

IS may have overreached itself; its policies may not be sustainable and it faces determined opposition from Sunni and Shia Muslims alike. Interestingly Saudi Arabia, with its impressive counterterrorist resources, has already thwarted IS attempts to launch a series of attacks in the kingdom and may be the only regional power capable of bringing it down. The shooting in Canada on 22 October, where a Muslim convert killed a soldier at a war memorial, indicates that the blowback in the west has begun; to deal realistically with our situation, we need an informed understanding of the precise and limited role of Islam in the conflict, and to recognise that IS is not an atavistic return to a primitive past, but in some real sense a product of modernity.

Karen Armstrong is the author of “Fields of Blood: Religion and the History of Violence” (Bodley Head, £25)