MOSUL, Iraq — Gunfire echoes through the pockmarked streets as Maj. Ihab Jalil al-Aboudi's soldiers fight block by block for the northern Iraqi city of Mosul, occasionally pausing to help terrified families flee to safety across the rubble.

Associated Press reporters accompanied his forces for three weeks in May as they battled Islamic State militants in neighborhoods around Mosul's Old City, part of a massive offensive launched in October that Iraqi commanders hope to finally complete in the coming days.

Driving the Islamic State from Iraq's second largest city would hand a major defeat to the extremist group three years after it swept across much of northern and central Iraq. But victory has come at a heavy cost for Mosul's residents and the soldiers fighting to liberate them from the extremists' rule.

On a hot afternoon, al-Aboudi helped a group of civilians — men, women and children — navigate a narrow escape corridor opened up by his forces.

"Thank God for your safety," he said, over and over again, as he handed them bottles of water. "Lift your veils!" another soldier called out, signaling to the women that they were no longer bound by the IS group's harsh interpretation of Islamic law.

A day after Iraq had declared the area liberated, there was still scattered gunfire and explosions from airstrikes by the U.S.-led coalition. The streets were littered with the bodies of Islamic State militants who had fought to the death.

Al-Aboudi is the fourth commander to take charge of the unit since the Mosul offensive began eight months ago. One of his predecessors was killed in action and another was wounded.

"We have become more experienced in dealing with the civilians in an operational zone," he said. "We rescue civilians during clashes between us and the terrorist gang."

More than 850,000 civilians have fled their homes since the battle for Mosul began, but tens of thousands more have stayed despite the heavy fighting.

A few blocks away from the front line, Faisa Muhammed, her children and grandchildren sheltered in their home. The force of nearby explosions had blown out all their windows and wounded her grandson, Hadi, who protectively plugged his ears even when it was quiet.

"It is normal," Muhammed said, taking stock of her family's experience of three years of militant rule. "They destroyed us."