BAGHDAD — Iraqi forces have driven Islamic State fighters from the northern city of Hawija, the militants’ final urban stronghold in Iraq, three years after they seized control of nearly a third of the country, the Iraqi government said Thursday.

Iraq’s prime minister, Haider al-Abadi, said in a televised appearance in Paris, where he is on a state visit, that Hawija had been “liberated,” calling it a “victory not just for Iraq but for the whole world.”

The United States-led coalition confirmed the fall of Hawija, calling it “a swift and decisive victory” by the Iraqi forces.

Although fighting continues in surrounding districts, the loss of Hawija adds to a series of crushing blows for the militants in Iraq, who are left in control of only a string of desert outposts in the Euphrates River valley and the city of Qaim, on the border with Syria.