In early June 2014, the Islamic State onslaught on Iraq’s second city Mosul caught most observers by surprise.
Mosul, with a population of 1.8 million, was overrun in just a few days, even though an estimated 800 Islamic State fighters were hugely outnumbered by around 30,000 Iraqi soldiers. The army simply turned and fled.
Reports that ISIS stole some $430 million from Mosul financial institutions have never been confirmed, but the group was certainly able to loot vast quantities of U.S.-supplied Iraqi army equipment and military hardware.
In the days after it took Mosul, the Islamic State surged onward through Iraq, capturing parts of the mainly Sunni Nineveh, Salahuddin and Diyala provinces. Along the way it sparked terror among the local population by its brutal treatment of non-Sunni Muslims and summary executions of army soldiers.
In early July, a film was released showing Islamic State leader Abu Bakr al-Baghdadi making his first public appearance in years. From the lectern of Mosul's main mosque, he declared an Islamic caliphate with him as its ruler.
The group's rampage caused the displacement of around 1.2 million Iraqis. Emboldened by its success, the Islamic State also launched an offensive on areas to the west and north of Mosul, clashing with Kurdish forces there.
ISIS seemed unstoppable; it seized the Mosul dam and came ever closer to Erbil, the capital of autonomous Iraqi Kurdistan.
The impact on Iraq’s minorities was particularly grim, as the Islamic State strove to permanently remove them from areas where they had lived for centuries. Religious groups including Christians, Yazidis and Turkmen were subjected to summary executions, torture and sexual violence. Sites of immense historical and cultural importance to these groups were systematically destroyed.
Human rights groups reported that the abuses against the Yazidis, a pre-Islamic sect viewed as heretic by the Islamic State, could amount to genocide. In August 2014, as many as 5,000 Yazidi men were reported killed during an ISIS advance in Sinjar, northern Iraq, with tens of thousands of civilians fleeing into the mountains.
Women from smaller minority groups have been at particular risk of sexual abuse and forced marriage. Dabiq, the English-language Islamic State magazine, dedicated much of its October 2014 issue to a discussion on how Yazidi women could be enslaved.
Part of the reason ISIS could gain so much ground in Iraq was its exploitation of the Sunni minority's grievances.
The Shi'ite-dominated government of Nouri al-Maliki, in power for eight years, exacerbated sectarian tensions, and ISIS forged alliances with many Sunni tribal leaders and militias.
Growing pressure from the United States, which felt that sectarian tension could not be addressed if Maliki remained in place, led to his replacement in mid-August 2014 by Shi'ite politician Haider al-Abadi.
A Shi'ite volunteer force backed by Iran – al-Hashd al-Shaabi, the Popular Mobilization Forces – was formed in response to the Islamic State onslaught in June 2014. Comprised of numerous militias, it could draw on tens of thousands of fighters and helped beat back ISIS.
Overall, in the first six months of 2015, the Islamic State was forced to retreat from numerous locations in Iraq, while at the Syrian border town of Kobani an intense three-month battle ended in an ISIS retreat.
In Iraq, Tikrit was retaken in April 2015 by government forces, Shi'ite militias and local tribes with the help of air support. Kurdish fighters, with support from the U.S.-led coalition including air cover, retook territory in the north.
But attempts to take back Mosul failed. And although the combined efforts of actors as disparate as the Iraqi, Kurdish, Iranian and U.S.-led coalition pushed the Islamic State back in some areas, the group has retained key territory in Iraq. Although the air campaign has restricted ISIS' freedom of movement, decisive defeat is only possible with the use of effective ground troops.
The Islamic State has strengthened its control in some parts of Iraq, notably in Anbar province, and received a major boost with the conquest of Ramadi in May 2015. That led to reports that it was poised to assault Baghdad just 60 miles away. Although those fears were overstated, ISIS remains a formidable force in Iraq, even though much of the ground it controls is made up of desert.
As far as the self-styled caliphate is concerned, with territory comes legitimacy.