2017 will be remembered as the year the Islamic State group's ultra-violent statehood experiment was terminated, but Iraq and Syria are now left staring at ruined cities and daunting challenges.
The jihadist group lost its two main hubs, Mosul in Iraq and Raqa in Syria, earlier this year and is now only clinging to the dregs of a "caliphate" that spanned territory the size of Britain three years ago.
The proto-state shrank all year as a hail of air strikes conducted by Iraq with its US-led allies and Syria with its main Russian backer paved the way for an inexorable territorial reconquest.
This month, Iraqi Prime Minister Haider al-Abadi announced that for the first time in four years IS controlled no significant territory in Iraq.
In neighbouring Syria, some work remains to be done, but IS holds only scattered and isolated pockets.
In Iraq, the West threw its weight behind Abadi, who has defied the odds to keep his seat and gain internal credibility as he steered the country through three years of anti-IS war.
The costly military fightback was also a chance to rebuild an army whose collapse in Mosul played a large part in the lightning expansion of the IS caliphate in 2014.
The US-led coalition has trained 125,000 members of the security forces since then, and the country's elite counter-terrorism units that spearheaded the fight against IS are arguably the world's most battle-hardened regular force.
"Daesh is finished from a military point of view but not as a terrorist organisation... we must remain in a permanent state of alert," said Ahmed al-Assadi, spokesman for the Hashed al-Shaabi paramilitary organisation that had a major role in the war.
The status of the Hashed, which is dominated by Shiite militia groups whose loyalty is more to Tehran than Baghdad, will be one of the greatest challenges for Iraq in the coming months.
The country will also have to inject life back into Sunni cities that have been extensively destroyed, including the second city Mosul, Baiji, Ramadi, Sinjar and Fallujah.
Failure to do so quickly, observers say, would give the remnants of IS -- or its next incarnation -- a chance to emerge from the desert canyons where they are hiding and thrive afresh on the back of renewed sectarian discord.
Syrian cities such as Aleppo, Raqa, Homs and others also need extensive reconstruction.
President Bashar al-Assad is much less palatable to the international community than Abadi, who enjoys good relations with the West as well as with Iran and other neighbours.
During 2017, a peacetime feel returned to parts of Damascus and some areas elsewhere in the country where the fighting ended two or three years ago.
But while IS's final military defeat in Syria is in no doubt, the war there is not yet over and large-scale military operations against anti-regime forces are still under way.
Several so-called "de-escalation zones" across the country have yielded mixed results and successive rounds of international negotiations to end a conflict that has killed around 350,000 people in less than seven years have yet to bear fruit.
Kurds pushing for more autonomy and supported by the US now control a large area of the country, a standoff with Damascus that many fear risks sparking renewed fighting.
Indeed, on Monday Assad referred to the Kurdish fighters who battled IS as "traitors".
"A big problem might be if a new security vacuum emerges, for example if the regime and the (Kurdish-dominated) Syrian Democratic Forces go to war against each other," said Syria analyst Aymenn al-Tamimi.
Since the end of the nine-month operation to retake Mosul -- the largest urban battle since World War II -- and the assault to wrest back Raqa that ended in October, the scale of the fighting has tailed off.
2018 could even be the year Syria's deadly conflict is declared over, but the humanitarian crisis in both Iraq and Syria still festers, prompting record appeals for aid.
Around three million Iraqis are displaced while half of Syria's 22 million inhabitants have been forced from their homes by the conflict.
A growing number of Syrians are returning home, but "while some areas have become safer this year, fighting has erupted in other places causing huge waves of displacement", said Ingy Sedky, ICRC spokesperson for Syria, adding that a million people were displaced this year alone.
In Iraq, 11 million people require humanitarian assistance and colossal reconstruction needs are not the only challenges.
"Thousands are in detention following these rounds of conflict," said Patrick Hamilton, ICRC Deputy Regional Director of the Near and Middle East.
"How they are treated, and how justice is carried out will have a critical impact on creating a sustainable peace, or gestating the next round of violence," he said.