Iraqi Prime Minister Haider al-Abadi speaks Dec. 9 at an Arab media conference in Baghdad. (Iraqi Prime Minister Media Office/via Reuters)

Iraq's prime minister declared an end Saturday to the war against the Islamic State, more than three years after militants overran and captured ­one-third of the country, and imposed a violent and austere rule over millions of Iraqis.

Haider al-Abadi announced that the rugged, sparsely populated desert region bordering Syria has been “cleansed” of Islamic State fighters and that the porous border that had underpinned the self-declared caliphate that straddled both countries has been fully secured.

“This victory was achieved . . . when Iraqis united to face a heinous enemy that didn’t want us to see this day,” Abadi said. “They wanted to return us back to the Dark Ages.”

Saturday's declaration caps a war that has killed thousands of Iraqi troops in fierce battles for such cities as Tikrit, Ramadi and Baiji since 2015. But after losing the grueling nine-month battle for Mosul in July, the Islamic State began to quickly collapse — ceding its grip on smaller cities and towns in days rather than months.

The explosive rise of the militants in 2014 drew the United States back into Iraq, with more than 5,000 U.S. troops assisting Iraq’s military as it wrested back land. The Islamic State’s growth also saw the United States enter Syria’s battlefields, already crowded with Russian and Iranian-proxy forces that buttressed the unsteady rule of President Bashar al-Assad.

“The Coalition congratulate the people of Iraq on their significant victory against #Daesh. We stand by them as they set the conditions for a secure and prosperous #futureiraq,” the U.S.-led coalition wrote in a tweet, using the Arabic name for the Islamic State.

Last month, Iran and Russia declared victory over the Islamic State in Syria, though fighting continues in small pockets near the border with Iraq. The Syrian Democratic Forces, a group of mostly Kurdish fighters backed by the United States, won back the Islamic State’s de facto Syrian capital of Raqqa in October.

Abadi's comments came almost in passing as he attended a conference with the journalists' union Saturday. The casual declaration of victory over the Islamic State came as the nation's attention has turned to a political standoff with Kurdish separatists and a reckoning with repairing the immense physical and social damage the militants and the military fight to dislodge them have wrought.

Later, in a 10-minute speech broadcast on national television, Abadi stood before columns of soldiers and police in front of the defense ministry and congratulated Iraqis on their victory. He highlighted national unity as the engine that powered the war against the Islamic State, telling Iraqis to “hold their heads high.”

Abadi said the coming fight will be against rampant corruption, saying it is a natural extension of the war to bring Iraq’s resources back into the hands of the nation’s citizens.

Although a large military parade to mark the victory is planned for the coming weeks, Abadi’s announcement provoked little public jubilation, reflecting a mood in the country that is still grappling with its losses.

The Pentagon has acknowledged that at least 801 civilians have been mistakenly killed in U.S.-led airstrikes against Islamic State targets in Iraq and Syria. Airwars, an independent monitoring group, says the figure is likely much higher, totaling 5,961 since 2014.

Last week, an Iraqi official charged with managing a fund to reconstruct cities such as Mosul said it would cost about $150 billion to rebuild these places — the majority of which are in Iraq’s Sunni heartland. About 3 million people remain displaced to this day.

In addition, 20,000 people accused of joining the Islamic State remain in detention, coursing through an overburdened criminal justice system that the Human Rights Watch said last week is unable or unwilling to provide fair trials and distinguish between those who eagerly killed for the group or were coerced into menial roles such as cooks.

Iraqi forces are also bracing for the Islamic State’s continued presence as an underground insurgency that has returned to its traditional tactics of terrorist attacks. Hours before Abadi spoke, a car bomb in Tikrit killed at least one person.

Abadi, who has won plaudits in Iraq for his posture of inclusion and efforts to reverse nearly a decade of his predecessor's sectarian policies that favored Shiites, has insisted the conditions that gave the Islamic State rise would return if there is no genuine nationwide move toward reconciliation.

The appetite for such a reconciliation will be tested as campaigning for national elections slated for May 2018 has begun. Powerful Shiite militias that played a significant role in freeing Sunni lands occupied by the Islamic State are expected to field dozens of candidates, some of whom are closely aligned with Iran and embrace a sharply sectarian narrative that pins the Islamic State’s rise on widespread support by Iraq’s Sunnis.

Abadi has insisted that the militia figures who want to contest elections must disarm, a demand many Iraqis see as impossible to impose given how deeply enmeshed the militias are in Iraq's security apparatus. Badr Organization, one of the oldest and largest Iran-backed Shiite militias in Iraq, already controls the interior ministry and holds 22 seats in parliament.

In his speech on Saturday, Abadi hinted at this looming challenge.

“The only way to build a state and achieve justice and stability is by keeping arms under the control of the state and the rule of law,” he said.

Mustafa Salim contributed to this report.

Read more: