Iraqi government forces flash the "V" for victory sign in Fallujah after retaking the embattled city from the Islamic State militant group. (Haidar Mohammed Ali/AFP/Getty Images)

Iraqi commanders said Sunday that they had completely retaken the city of Fallujah after a month-long battle, depriving Islamic State militants of a symbolic stronghold just an hour’s drive from the capital.

There was a celebratory mood in the city as pickup trucks ferried around cheering members of the security forces, who unloaded volleys of bullets into the air in jubilation. While the city appeared to be under their control, commanders conceded that militants could be hiding out.

The Sunni city 45 miles west of Baghdad was the first in Iraq or Syria to be captured by the Islamic State, about 21 / 2 years ago. Fallujah was a quagmire for U.S. service members during the Iraq War, so there were expectations that it could be a bloody and drawn-out fight this time, too. But the Iraqi military made quick progress after breaking through defense lines outside the city earlier this month.

The loss of Fallujah deals a significant blow to the Islamic State’s self-proclaimed caliphate, which has been steadily shrinking as Iraqi forces have advanced with the help of airstrikes from a U.S.-led coalition. Even before the Fallujah operation, the militant group had lost an estimated 40 percent of the territory it once controlled in Iraq.

But parts of the Sunni city, once home to 300,000 people, are still laced with roadside bombs. In the narrow streets of the old-city area, secured earlier Sunday, an officer urged caution as he pointed out a booby trap, its yellow wires leading out of the ground and over the gate into a nearby house.

“Danger explosives,” someone had written on the wall. Thamer Ismail, a commander with the Iraqi police’s rapid reaction force, also known as S.W.A.T., said his forces had detonated two booby-trapped houses and 13 roadside bombs on Sunday alone.

While S.W.A.T. and federal police forces focused on the older area of the city, Iraq’s special forces stormed the Jolan neighborhood Sunday morning.

Standing on a street corner, Capt. Mudher Moussawi from the federal police said the operation for the old-city area had faced little resistance. Only about 30 militants were defending it, he said.

“But there may be fighters in the houses,” he said, pointing down a road toward a mosque. “Lots of streets are not yet cleared.” Many were blocked with dirt and the shells of burned cars, makeshift defenses against Islamic State car bombs.

While some neighborhoods, particularly on the outskirts of the city, have suffered extensive damage, others are largely intact, raising hopes among residents who were forced to flee. Tens of thousands are now stuck in desert camps with little assistance.

“It’s still too early to speak of returns,” said Nasr Muflahi, the Norwegian Refugee Council’s Iraq director. “We just do not know which areas are safe and which aren’t.”

The actions of the Shiite-led government’s security forces in this “City of Mosques” — the most important in Iraq for Sunni Muslims — have been highly scrutinized.

Given concerns about reprisal attacks, Iraq’s government initially announced that its popular mobilization units — armed groups largely made up of Shiite militias — would not be entering the battle inside the city. Many among Iraq’s Shiite militias view the local population as largely sympathetic to the militants.

However, forces from the Shiite Badr Organization had been fighting alongside police in recent days, commanders said.

“In the beginning, we decided to only support them,” Hadi al-Amiri, a member of the Badr group, said during a visit to the S.W.A.T. base. “But they found that they couldn’t do it alone. Therefore, we entered the city.”

He said the popular mobilization units had held back until civilians had left.

Plumes of black smoke billowed out of houses in an area under the control of police and militia forces.

Amiri denied that militia forces were setting properties ablaze. He said that the burning houses were the result of the fighting or Islamic State militants setting fire to their bases as they retreated.

“An electrical fire,” said one officer, when asked to explain a burning building that hadn’t been alight a few hours before, after Islamic State militants had left the area.

Prime Minister Haider al-Abadi visited the city Sunday afternoon, speaking outside its main hospital.

He said that some “sick souls” may have committed violations “here and there” but that they were isolated incidents and unacceptable. He said it was a day for all Iraqis to celebrate.

“We had promised that we would raise the Iraqi flag high in Fallujah, and we have fulfilled this promise, and we will raise it soon in Mosul,” Abadi said as he hoisted the national banner. Mosul, about 250 miles northwest of Baghdad, remains the last significant Iraqi city in the hands of the militants.

“Iraqi forces have proved that they have the capability to liberate all their land,” Abadi said.

Iraqi commanders attributed their rapid progress in Fallujah to the Islamic State’s weakness after being besieged by security forces for months and to a growing backlash in the city against the militant group’s rule.

More than 1,800 Islamic State fighters were killed in the offensive, Lt. Gen. Abdelwahab al-
Saedi, commander of the Fallujah operation, told state television. That is more than double the estimates provided by security forces for the number of fighters in the city before the operation began.

But some cautioned that completely defeating the Islamic State requires more than just military operations.

“We’ve fought the militants, but we haven’t fought the ideology,” said Brig. Gen. Dawood al-
Shammari, another S.W.A.T. commander.