Iraqi government forces during operations Thursday west of Baghdad near Fallujah. (Moadh Al-Dulaimi/Agence France-Presse via Getty Images)

— Iraqi Prime Minister Haider al-Abadi on Friday declared victory over the Islamic State in Fallujah after a day of rapid advances as security forces pushed deep into the city center, dislodging the militants who have controlled it for nearly 2½ years.

In a televised address, Abadi said that some “pockets” of resistance remained in the city, about 45 miles west of Baghdad, but that it was largely under the control of security forces. Earlier in the day, Iraqi forces raised the country’s flag over the local council building, while commanders reported that they had retaken a string of neighborhoods as the militants abandoned their positions.

The Islamic State has been “broken” in the city, said Col. Abdelrahman al-Khazali, a police spokesman.

But the gains also compounded a growing humanitarian crisis in the surrounding province of Anbar, as thousands of civilians who had been trapped inside the city took advantage of the Islamic State’s collapsing grip to flee. Aid agencies working with the displaced said they were struggling to provide even basic assistance. Tents had run out, and food and water supplies were dangerously low.

Defeating the Islamic State in Fallujah deprives the group of one of its last strongholds in Iraq and gives a boost to the embattled Abadi.

Backed by airstrikes from the U.S.-led coalition, Iraq’s special forces have won a series of victories against the Islamic State elsewhere in the western province.

Fallujah, though, holds particular importance. Dubbed the “City of Mosques,” it is of symbolic significance to Sunni Muslims and was the first Iraqi city to fall to the militants. It was in Fallujah that U.S. forces endured their bloodiest fighting of the Iraq War, battling the Islamic State’s predecessor, al-Qaeda in Iraq, on the city’s streets 12 years ago.

“We promised to liberate Fallujah, and today Fallujah was returned to the bosom of the country,” Abadi said in his speech.

He went on to address the militants directly.

“Your leaders have made promises to you and let you down. They promised you that they would withstand, and they didn’t,” he said. “You have no place in this Iraq.”

After beginning their initial assault last month, Iraq’s elite special forces encountered a complex network of booby traps on the city’s outskirts.

They said they expected the barricades to be easier to overcome once they broke through the city’s initial defense lines, and they hoped that a months-long siege of the city had weakened the militants inside.

That appeared to be ringing true Friday as Iraqi forces made faster-than-expected gains.

The militants “realized it’s a lost cause, and they are running away,” said Maj. Gen. Saad Harbiya, an Iraqi army commander.

Lt. Gen. Abdelwahab al-Saedi, commander of the Fallujah operation, said Iraq’s elite counterterrorism forces had surrounded the city’s hospital, which he said the militants were using as a base.

The hospital was an early target for U.S. forces and Iraqi troops as they began an assault on the city in 2004.

Saedi said his forces were within 50 yards of the building and were preparing to storm it. However, the presence of “some civilians” inside was delaying the operation, the Iraqi military later said.

Commanders reported that the neighborhoods of Nazzal, Saray, Sinai and Andalus, and the main cemetery, had all been retaken. The central Jolan and Mualimin neighborhoods had not yet been secured, commanders said.

Sabah al-Noori, a spokesman for Iraq’s counterterrorism forces, predicted that the entire city would be under the control of Iraqi government forces “soon.” Abadi said he expected the final militants to be expelled within hours.

Abadi announced the operation to regain control of the city last month, going against the advice of the United States to instead focus on the larger Islamic State-held city of Mosul farther north.

Abadi, however, has been under domestic pressure to score a quick win against the militants after mass street protests in Baghdad against his government. Mosul is a more politically complicated operation, involving coordination between Baghdad and the semiautonomous government in Iraq’s northern Kurdistan region.

There have been concerns about the plight of civilians stuck inside Fallujah. When the operation began in late May, as many as 90,000 people were believed trapped in the city, with the Islamic State holding them to use as human shields.

Adding to those worries is the supporting role being played by Shiite militias, which commonly perceive civilians in the Sunni-majority city to be sympathetic to the Sunni extremists. The militia forces have agreed not to enter the city center but have been accused of rights abuses on its outskirts as civilians flee.

The Norwegian Refugee Council said the sudden surge of fleeing civilians was “overwhelming.”

A sudden retreat by Islamic State fighters from key checkpoints in Fallujah allowed residents to leave in “droves,” spokesman Karl Schembri said. The aid group does not have exact figures on how many have left, he said.

“It’s total chaos,” he said. Thousands had slept in the open overnight and were now in the scorching sun with no shelter as temperatures climbed over 100 degrees, he said. Tents had run out.

“Drinking water remains in dangerously short supply,” he added.

Falah al-Issawi, deputy head of the Anbar provincial council, said 63,000 civilians had fled the operation in Fallujah. The International Organization for Migration put the number at 68,000.

They join hundreds of thousands displaced from other areas of Anbar, including the provincial capital, Ramadi, which was recaptured at the end of last year. Most have not been allowed to return home, because large areas of the city have been reduced to rubble and are not yet cleared of explosives.

Deemed a security threat, the displaced are also not allowed to cross into neighboring Baghdad province without special permission. Abadi tried to assure the displaced that security forces had sacrificed their lives so they could return to live in “security and peace.”

Men who have fled have been detained for security screening. Out of 7,000 detained, about 1,500 have been referred to the judiciary for suspected ties to the Islamic State, said Issawi, who heads the screening committee. Another 1,500 are being investigated, while the rest have been released, he said.

Grand Ayatollah Ali Sistani, Iraq’s top Shiite cleric, urged security forces to take care as they advance and treat civilians as “brothers and sisters.”

“We warn that the aim of the fighters should not be revenge,” he said in his sermon, urging “discipline.”