IRBIL, Iraq — Thousands of fighters flocked to join Iraq’s state-sanctioned, Iran-backed Shiite militias Sunday, advancing to cut off Islamic State extremists holed up near Mosul in northern Iraq while bombers killed at least 17 people in Shiite neighborhoods of Baghdad.

Militia spokesmen said that some 5,000 fighters had joined their push to encircle from the west the country’s second-largest city of Mosul, the militants’ last bastion in Iraq, which is linked by road to territory it holds in Syria.

Karim al-Nuri of the militias’ umbrella group, known as the Popular Mobilization Units, and Jaafar al-Husseini, a spokesman for unit member the Hezbollah Brigades, said that a total of some 15,000 Shiite fighters were now participating in the battle.

The Iraqi military confirmed the figures, which, including army units, militarized police, special forces and Kurdish fighters, would bring the total number of anti-extremist forces in the offensive to over 40,000.

The two-week-old offensive to drive the Islamic State from Mosul had been long-anticipated, since the Sunni extremists stormed into the city in 2014 and drove out a much larger Iraqi force, albeit one that was demoralized from neglect and corruption.