After three years of violence, Islamic State has encountered a major defeat that could mean that its end is near. On July 10 2017, Iraqi Prime Minister Haider Al-Abadi, after a successful nine-month military offensive to "liberate" the northern city of Mosul, declared "total victory" over IS in Iraq.
He categorically said: "I announce from here the end and the failure and the collapse of the terrorist state of falsehood and terrorism which the terrorist Daesh announced from Mosul", using the Arabic acronym for ISIS or ISIL.
Almost exactly three years ago, on June 29 2014, Abu Bakr Al-Baghdadi, the group's self-styled caliph, proclaimed a cross-border caliphate stretching over vast swathes of northwestern Iraq and eastern Syria.
Today, the Iraqi half of that territory has been almost totally eliminated (the northwestern Iraqi city of Tel Afar, close to the Syrian border, being an exception) while the Syrian half, based in the city of Raqqa, is facing imminent collapse under powerful US-backed Kurdish-led military offensives.
It's a major turning point.
In the summer of 2014, an ISIL blitzkrieg swiftly defeated Iraqi defence forces across northwestern Iraq, capturing some 40% of Iraqi territories.
Prior to this rapid conquest, ISIL fighters had captured the Syrian province of Raqqa in January 2014, taking advantage of the bloody civil war let loose by pro-democracy movements.
But the territorial conquests could not be sustained for long. After a string of crushing military defeats throughout 2015 and early 2016 at the hands of Iraqi and Syrian armed forces, ISIL lost 65% of its Iraqi territories and 45% of captured ground in Syria.
When Raqqa falls - sooner or later - to Kurdish-led forces, it could mean the complete destruction of the caliphate.
What went wrong with ISIL?
Al-Baghdadi, whose fate is currently unknown, declared his caliphate to realise a series of "impossible" objectives - including restoring Islamic power under a single authority, eliminating US and Western influence on Muslim lands and laying a claim to global leadership - and called upon all Sunni Muslims from Europe to East Asia to unite under his new flag.
These were the same objectives that the now-deceased al-Qaeda leader Osama bin Laden boastfully proclaimed in the early 1990s.
They were also unrealistic goals given the policy choices and capabilities of ISIL. In his first official speech on June 29 2014, Al-Baghdadi presented a world divided into two mutually opposed camps: Islam, and the camp of disbelief and hypocrisy.
He put pro-caliphate Sunni Muslims in the camp of Islam while the camp of disbelief was the abode of Shia Muslims, Jews, Christians and almost everybody else. This set the new caliphate on a collision course with the rest of the world.
ISIL militants, like their Wahhabi counterparts in the Gulf, also declared Shias to be non-Muslims and viewed the sheikhs, kings and emirs of the Gulf region as American surrogates, ringing alarm bells in Iran and Saudi Arabia.
The spectre of the threat they posed soon forced Iran, Saudi Arabia and the US to close ranks to militarily deter and contain ISIL together, despite their differences.
Lack of followers
The spate of atrocities committed by ISIL fighters against the Yazidi community in Syria, who practice a non-Islamic faith, led the United Nations to accuse ISIL of perpetrating genocidal crimes.
This senseless use of violence against non-Muslims alienated most Sunni Muslims, so ISIL was never able to develop much popular support. Less than 8% of Sunni Muslims in the top 20 Muslim-majority countries across the Middle East, North Africa and Southeast Asia supported the ISIL caliphate.
In early December 2015, to ISIL's despair, thousands of Muslim clerics from across the globe declared the caliphate a terrorist organisation and branded its supporters non-Muslims.
ISIL's military defeats, loss of territories and control over resources represented further serious blows.
Two years later, after territorial losses in Iraq and Syria meant fewer people and businesses to tax, that revenue was more than halved to US$870 million. Its control over oil fields - a lucrative source of money - also shrank from 2014 to 2016.
ISIL's challenges and legacies
ISIL might be on its way to becoming history, but it will certainly leave its mark.
Just as its emergence posed a twofold challenge (territorial as well as ideological) to the Middle East and the West, ISIL's demise is also leaving behind the legacies of sectarian violence and killing, inter-ethnic malice and seemingly unmanageable rivalries involving regional and extra-regional powers.
Rightly or wrongly, many commentators saw the declaration of the cross-border ISIL caliphate as a possible death blow to the post-first world war political arrangements in the region.
Present-day national borders in the Middle East are the outcome of a secretly negotiated agreement between Britain and France from May 1916, known as the Sykes-Picot Agreement. It divided the Ottoman Arab territories of the Levant, Jordan, Iraq and Palestine between Britain and France.
Half a dozen Arab states were created: Iraq, Jordan, Syria and Lebanon. Israel, originally created as a "homeland" for the Jewish people in 1917, declared itself a state in 1948.
The caliphate partially challenged British- and French-imposed national boundaries by systematically dismantling the Iraq-Syria border, redrawing the map. It also expressed its resolve to eradicate colonial legacies in the region by extending the boundaries of the caliphate.
This attempt to rewrite the history of the Middle East may keep destabilising the region for years to come.
Ideologically, ISIL has challenged the West's eurocentric claims to universalism, in which Western values of democracy, human rights and freedom are promoted as universal values that are applicable to all societies, regardless of cultural and racial differences.
Though criticised by many people from within the West, eurocentrism is alive in the hearts and minds of many Western people. The 2003 US invasion to remodel Iraqi society on American lines is just one example.
ISIL rejects Western dominance over the Middle East and has sought to promote the alternative Islamic claim to universalism based on the commandments of the holy Koran.
The Koran instructs all humans to engage in universal morality by creating and upholding a moral order based on the values of justice, equality, truthfulness, fairness and honesty. This applies to all humans, regardless of their ethnic, cultural and racial differences.
Claiming a universal moral order that negates Western values could not but pit ISIL against the West. Future Islamic radical groups, if they emerge, are likely to carry on the ideological battle.
They may well do so in less violent ways. The Koran does not sanction brutal and inhumane methods to fulfil its commandments.
The mess after ISIL
The possible end of ISIL could still mean a more unstable Middle East, at least in the short term.
Currently, most Iraqi factions have morphed into a common front against ISIL, hiding the mistrust and rancor that persists between Shia and Sunni Iraqis, among diverse militia groups, and between Arab and Kurdish Iraqis.
If ISIL disappears, this tentative, temporary alliance may simply fall apart, unleashing more violence on the war-ravaged nation.
Syrian society is likewise polarised; along divisions between the foreign-backed pro and anti-government groups and between the rebel groups themselves. These tensions will outlive ISIS.
The elimination of ISIL will reaffirm the region's post-first world war political and territorial status quo but don't expect it to bring peace to the Middle East.