Thousands of people are fleeing Mosul after Islamic militants overran parts of Iraq's second-largest city. Militants from the breakaway al-Qaeda group, the Islamic State of Iraq and the Levant (ISIL) and Iraqi troops have been fighting for days in Mosul.

Insurgents armed with machine guns and rocket-propelled grenade launchers stormed the provincial headquarters building, overpowering guards in a short firefight, according to Ali Mahmoud, the media official for Nineveh province.

Families fleeing violence in Mosul, capital of the northern Nineveh province, gather at a checkpoint. AFP

On Monday night and into Tuesday, the government forces in the city appeared to collapse. Prime Minister Nouri al-Maliki has declared a state of emergency.

Regaining Mosul poses a daunting challenge for al-Maliki. The city has a Sunni Muslim majority and many in the community are already deeply embittered against his Shiite-led government. During the nearly nine-year American presence in the country, Mosul was a major stronghold for al-Qaeda. US and Iraqi forces carried out repeated offensives there, regaining a semblance of control but never routing the insurgents entirely.

ISIL, which was once al-Qaida's branch in Iraq, was thrown out of the terrorist network after it expanded its operations in Syria against the orders of al-Qaida leader Ayman al-Zawahiri. It is considered one of the most ruthless rebel forces fighting to topple President Bashar Assad in Syria, where it has in seized a major city in the east and other territory.

In Iraq, the group rose up earlier this year to take over Fallujah and parts of the nearby city of Ramadi, the capital of Anbar province. It has also been carrying out a campaign of bombings and other violence in Baghdad and other parts of the country.