BAGHDAD — Iraqi forces quickly entered central areas of Falluja on Friday after weeks of battling the Islamic State, fighting that had forced thousands of civilians to flee and overwhelmed the ability of aid agencies to care for them.

Reporting little resistance from Islamic State fighters, counterterrorism forces raised the Iraqi flag over the main government building in central Falluja, officers and state television reports said. They said that pro-government forces moved on to besiege the city’s main hospital, which was the first target of American forces when they invaded the city in 2004 and in recent months has served as a headquarters complex for the Islamic State.

The rapid and unexpected gains suggested a shift in tactics by the Sunni extremists of the Islamic State, also known as ISIS or ISIL, or perhaps a sign of their weakness, as they abandoned their dug-in positions and regrouped in western neighborhoods of Falluja. That allowed thousands of civilians, who aid groups had said were being held as human shields, to flee across two bridges over the Euphrates River beginning on Thursday.