In June the leader of Islamic State declared the creation of a caliphate stretching across parts of Syria and Iraq - Abu Bakr al-Baghdadi named himself the caliph or leader. Edward Stourton examines the historical parallels and asks what is a caliphate, and what is its appeal?
When Islamic State (IS) declared itself a caliphate in June this year, and its leader Abu Bakr al-Baghdadi claimed the title of caliph, it seemed confirmation of the group's reputation for megalomania and atavistic fantasy. Al-Baghdadi insisted that pledging allegiance to this caliphate was a religious obligation on all Muslims - an appeal which was immediately greeted by a chorus of condemnation across the Middle East.
But is it dangerous to underestimate the appeal of IS? Al-Baghdadi's brutal regime does not, of course, remotely conform to the classical Muslim understanding of what a caliphate should be, but it does evoke an aspiration with a powerful and increasingly urgent resonance in the wider Muslim world.
The last caliphate - that of the Ottomans - was officially abolished 90 years ago this spring. Yet in a 2006 Gallup survey of Muslims living in Egypt, Morocco, Indonesia and Pakistan, two-thirds of respondents said they supported the goal of "unifying all Islamic countries" into a new caliphate.
Why do so many Muslims subscribe to this apparently unrealisable dream? The answer lies in the caliphate's history.
The Arabic khalifa means a representative or successor, and in the Koran it is linked to the idea of just government - Adam, and then David and Solomon, are each said to be God's khalifa on earth. And when the Prophet Mohammed died in 632 the title was bestowed on his successor as the leader of the Muslim community, the first of the Rashidun, the four so-called "Rightly Guided Caliphs" who ruled for the first three decades of the new Islamic era.
These four were, according to Reza Pankhurst, author of The Inevitable Caliphate, all appointed with popular consent. He argues that their era established an ideal of a caliph as "the choice of the people… appointed in order to be responsible to them, apply Islamic law and ensure it's executed". He adds that the true caliph "is not above the law".
Shia Muslims challenge this version of history - they believe that the first two caliphs effectively staged a coup to frustrate the leadership claims of the Prophet's cousin Ali - and this dispute about the early caliphate is the source of Islam's most enduring schism. But to today's Sunni Muslims, many of them living under autocratic regimes, the ideal of a caliphate built on the principle of government by consent is likely to have a powerful appeal.
Another significant source of the caliphate's appeal today is the memory it stirs of Muslim greatness. The era of the Rightly Guided Caliphs was followed by the imperial caliphates of the Umayyads and Abbasids.
"Seventy years after the Prophet's death, this Muslim world stretched from Spain and Morocco right the way to Central Asia and to the southern bits of Pakistan, so a huge empire that was all… under the control of a single Muslim leader," says historian Prof Hugh Kennedy. "And it's this Muslim unity, the extent of Muslim sovereignty, that people above all look back to."
This Islamic Golden Age was also marked by great intellectual and cultural creativity - the Abbasid court in Baghdad valued literature and music, and fostered world-changing advances in medicine, science and mathematics.
Yet these dynasties extended their rule so far, and so fast, that it became increasingly difficult for any one lineage to control all Muslim lands. As power fragmented, it was not just a political dilemma for any particular dynasty, but also a theological challenge to the very idea of the caliphate. The power of unity was closely linked to the idea of a caliph - yet it only took just over a century of the Muslim faith for the world to see parallel - and even competing - caliphates emerge.
The Sunni theologian Sheikh Ruzwan Mohammed argues: "While you do have two caliphs on earth proclaiming that they're the representatives of the Muslim community at this point, and more deeply that they are the shadow of God on earth, Muslims at that point were very pragmatic, and they acknowledged the fact that there could be more than one caliph representing the benefits and the concerns of the Muslim community - and that was also understood and accepted by Muslim theologians."
The Abbasid caliphate lasted for half a millennium before coming to a brutal end in 1258. When Baghdad fell to the Mongols, the last of the city's caliphs was rolled in a carpet and trampled to death under the hooves of Mongol horses - this was, bizarrely, a mark of respect, as the Mongols believed that people of rank should be killed without their blood being shed.
The institution of the caliphate, however, survived. Members of the Abbasid family were installed as titular caliphs in Cairo by the Mamluks, the main Sunni Islamic power of the day. They were more ornaments to the Mamluk court than anything else, but merely by existing they preserved the ideal of a single leader behind whom all Muslims could unite. So the title was still there for the taking when a new Islamic empire arose. Early in the 16th Century it passed - in slightly murky circumstances - to the Ottoman sultans, who ruled a new Islamic world power for a further 400 years.
The caliphate was finally extinguished by Kemal Ataturk, the father of modern Turkey, in 1924. He believed the abolition of the institution was essential to his campaign to turn what was left of the empire into a 20th Century secular nation state. The last Ottoman caliph was expelled from Istanbul to live out a life of cultured exile in Paris and on the Cote d'Azur.
But the institution he represented had by then existed for nearly 1300 years, and the impact of its abolition on Muslim intellectual life was profound. Salman Sayyid, who teaches at Leeds University and is the author of Recalling the Caliphate, compares it to Charles I's execution, which opened up so many profound questions about the roles of parliament and the crown. In the same way, he says, Muslim thinkers in the 1920s suddenly found they had to ask fundamental questions they had never confronted before: "Do Muslims need to live in an Islamic State? What should that state be like?"
By the mid 20th Century leaders like Egypt's Gamal Abdel Nasser had come up with an answer to those questions - the ideology known as pan-Arabism offered a kind of secular caliphate, and during the 1950s Nasser even established something called the United Arab Republic, which joined Egypt and Syria.
But everything changed in the Middle East with the foundation of the State of Israel, and Pankhurst argues that Pan-Arabism was wrecked on the rock of Israeli military might. "Pan Arabism drew its legitimacy from the fact that it was going to return the Arabs to their position of glory and liberate Palestine," he says. "When we had the abject defeat of 1967 (the Six Day War) it exposed a hollowness to the ideology."
Pankhurst belongs to Hizb ut Tahrir, an organisation founded in the 1950s to campaign for the restoration of the caliphate, and he argues that the revival of the idea has been driven by a general disenchantment with the political systems under which most Muslims have been living. "When people talk about a caliphate… they are talking about a leader who's accountable, about justice and accountability according to Islamic law," he says. "That stands in stark contrast to the motley crew of dictators, kings, and oppressive state-security type regimes you have, which have no popular legitimacy at all."
The regimes that dominated the Middle East during the late 20th Century did not like Hizb ut Tahrir - unsurprisingly, in view of its ideology. Pankhurst spent nearly four years in an Egyptian jail.
In the early days of the Arab Spring, the revolutions in countries like Tunisia, Egypt and Libya were interpreted in Western capitals as evidence that the Muslim future lay with democracy. Then in Egypt came the overthrow of the democratically-elected Muslim Brotherhood government by the army under General Abdel Fatah al-Sisi - and then came the horrors of Islamic State amid the bloody chaos of civil strife in Syria and Iraq.
"Many people will say that IS begins with al-Sisi's coup," says Salman Sayyid of Leeds University. "We right now have a growing gap of legitimacy in most governments that rule the Muslim peoples - and that gap isn't closing… One way of thinking about the caliphate is really a quest for Muslims to have autonomy. The idea that you should have capacity to write your own history becomes very strong and for Muslims I think the caliphate is the instrument for trying to write their own history."
Many classical Sunni scholars challenge the very notion that the caliphate is a political project. Sheikh Ruzwan Mohammed, for example, argues that the key to the caliphate is really spiritual. "I think the Islamic State should come from within," he says. "It should be an Islamic State first and foremost of mind and soul." And the overwhelming majority, even of those who do believe that a new caliphate is a realistic political objective, completely reject the violence espoused by the self-styled Islamic State.
But IS has skilfully exploited the elements in the caliphate's history which best serve its purposes. The historian Hugh Kennedy has pointed out, for example, that their black uniforms and flags deliberately echo the black robes the Abbasids adopted as their court dress in the 8th Century, thus recalling Islam's Golden Age. And their original title - the Islamic State of Iraq and the Levant - harks back to the days when there was no national border between the two countries, because both territories were part of the great Islamic caliphate.
The success of IS does, in a grim way, reflect what a powerful and urgent aspiration the Caliphate has become. The IS project is certainly megalomaniac and atavistic, but it is building on an idea that is much more than a fantasy.
Listen toThe Idea of the Caliphate, broadcast on Analysis on BBC Radio 4
Subscribe to the BBC News Magazine's email newsletter to get articles sent to your inbox.