ERBIL, Iraq — Kurdish forces exploited the mayhem convulsing Iraq on Thursday to seize complete control of the strategic northern oil city of Kirkuk as government troops fled in the face of advancing Sunni militants. The insurgents pressed their advance southward toward Baghdad, warned officials of occupied Mosul to renounce allegiance to the central government and threatened to destroy religious shrines sacred to Shiites.

At the same time, militias of Iraq’s Shiite majority rushed to fill the vacuum left by the abrupt disintegration in the government’s security forces, vowing to confront the Sunni militants, defend Baghdad and protect other threatened cities including Samarra, 70 miles north of the capital. Thousands of volunteers were reported to be mobilizing. “We hope that all the Shiite groups will come together and move as one man to protect Baghdad and the other Shiite areas,” said Abu Mujahid, one of the militia leaders.

The Sunni militants, who include many aligned with the jihadist Islamic State of Iraq and Syria as well as loyalists to the old Saddam Hussein government swept from power by the American-led invasion a decade ago, have confronted the government of Prime Minister Nuri Kamal al-Maliki with its worst crisis and threatened to plunge Iraq into a sectarian war. They routed government forces from the city of Mosul, Mr. Hussein’s home city of Tikrit and smaller cities closer to Baghdad this week in a lightning advance. The disarray in Mr. Maliki’s military, with many soldiers surrendering their American-made weapons and gear to the Sunni militants, has further compounded the crisis.