The Islamic State group, responsible for some of the worst atrocities perpetrated against civilians in recent history, appears on the verge of collapse.
After brutalizing residents living under its command for more than three years, the militants have now lost their self-proclaimed capital of Raqqa and are battling to hang on to relatively small pockets of territory in Iraq and Syria, besieged by local forces from all sides. Few, however, expect IS to completely go away, or for the bloodshed in the two countries and the region to end quickly.
Here's a look at the Islamic State group, the rise and fall of its “caliphate” and what to expect next:
A 'Caliphate' no more
IS, which emerged from the remnants of al-Qaida in Iraq, began its spread across the Mideast in early 2014, overrunning the Iraqi city of Fallujah and parts of the nearby provincial capital of Ramadi. In Syria, it seized sole control of the city of Raqqa after driving out rival Syrian rebel factions.
In June 2014, IS captured Mosul, Iraq's second-largest city, from where its leader, Abu Bakr al-Baghdadi, declared a self-styled “caliphate,” a declaration tantamount to an earthquake that would temporarily redraw borders and shake up the entire region.
IS promised justice, equality and an Islamic, religious utopia. But over the next few years, it terrorized people living under its control, systematically slaughtering members of Iraq's tiny Yazidi community, kidnapping women and girls as sex slaves, beheading Western journalists and aid workers and destroying some of the Mideast's spectacular archaeological and cultural sites.
IS also attracted a motley crew of foreign fighters, mostly marginalized European youths and other foreigners who took up its cause. But it alienated mainstream Sunni Muslims, who found IS' crude interpretation of Islam also spreading in areas far from Syria and Iraq.
Creating a territorial caliphate created a target, and an international anti-IS coalition soon took shape.
What's left
The United States launched its campaign of airstrikes against IS in Iraq in August 2014, and a month later in Syria. In Iraq, it partnered with government forces working with state-sanctioned Shiite-led militias as well as Iraqi Kurdish fighters known as peshmerga. In Syria, it partnered with local Syrian Kurdish-led fighters, the Syrian Democratic Forces.
Supported by tens of thousands of U.S.-led airstrikes, these forces drove IS militants from one stronghold after another over the years. The biggest blow came in July when Mosul, long regarded as IS' administrative capital, was liberated.
In Syria, IS appears to be heading for collapse as the U.S.-backed, Kurdish-led Syrian Democratic Forces, or SDF, and Syrian government forces, backed by their Russian allies, are attacking them in separate, simultaneous offensives.
A senior SDF commander on Tuesday said his forces liberated Raqqa from IS militants and would formally announce victory soon after clearing operations to remove land mines and search for sleeper cells. Mayadeen, a town in the heart of Syria's Euphrates River Valley near Iraq's border where the militants had been expected to make their last stand, fell to Syrian government troops over the weekend.
In northern Iraq, the jihadis no longer hold any cities or towns after their stronghold of Hawija fell earlier this month. Iraq's army is now gearing up to fight IS in its last territory - the sprawling desert Anbar province stretching all the way to the Syrian border. In Syria, IS still holds the town of Boukamal near the Iraqi border and scattered pockets of territory in the east.
Staggering price
The destruction of IS has come at a devastating cost for both Syria and Iraq, and immense suffering for those who endured the militants' brutal reign.
The fighting and airstrikes have pulverized once thriving cities, turning them into tragic vistas of crushed apartment blocks, flattened homes and collapsed roads and bridges. In Ramadi, Mosul and Raqqa, the scope of the damage is staggering.
Two weeks ago, the U.S.-led coalition announced it has returned more than 83 percent of IS-held land to local populations since 2014, liberating more than 6 million Syrians and Iraqis in the process. At least 735 civilians have been unintentionally killed by coalition strikes, although activists and war monitors estimate the toll to be much higher.
The nine-month battle to liberate Mosul resulted in the death of up to 1,500 Iraqi forces. At least 1,100 SDF fighters were killed in the battles for Syria's Raqqa and Deir el-Zour up until late September, according to the coalition.
In the three years since IS began building its “caliphate,” it has killed thousands of people, displaced millions and worked hard on infusing children with extremist doctrine.
Shitfting of sands
The rise of the Islamic State group and subsequent wars and alliances to bring about its defeat has worsened political and sectarian fault-lines in Syria and Iraq.
It gave unprecedented clout to Kurdish populations in both countries, unsettling their central governments, as well as Iran and Turkey, both battling Kurdish separatists within their own borders.
Under cover of the fight against IS, Iraq's Kurds seized the oil-rich city of Kirkuk in 2014 - a move Baghdad has now reversed, moving into the city, seizing oil fields and other infrastructure in an attempt to curb Kurdish aspirations for independence.
The shifting and chaotic battlefields in Syria's civil war, tensions between Kurds and ethnic Arabs, the presence of Shiite militias and government troops in predominantly Sunni towns and cities vacated by IS may lead to more violence.
In many ways, the fight over IS spoils and territories is only just beginning.
Uncertain future
All forces battling IS will have to remain vigilant even after they recapture the last militant-held territory. In some ways, they now face an even more daunting challenge.
Hisham al-Hashem, an Iraqi writer and analyst, estimates there remain 8,000 jihadis in Iraq's Anbar who will melt away “like salt in water” to wait for the right moment to launch their next insurgency or suicide attack.
IS affiliates continue to carry out swift attacks in Egypt and Libya, where the group gained a foothold and which could be its preferred theaters of retaliations. Before it broke away from al-Qaida and rebranded itself as the Islamic State, al-Qaida in Iraq waged a years-long insurgency following the 2003 U.S. invasion of Iraq, pushing the country to the brink of civil war.