BAGHDAD, Iraq - Kurdish troops and Iraqi Shiite forces exchanged mortar and machine-gun fire Sunday, in a flare-up that killed at least 12 people and raised concerns about the state's ability to control an array of armed militia groups as areas are freed from the Islamic State.

The fighting broke out in Tuz Khurmatu, an ethnically and religiously mixed tinderbox town that is 120 miles north of Baghdad. Both sides blamed each other for the conflagration.

The Islamic State was pushed out of the surrounding area in 2014, but the armed groups here have since jostled for control and influence. Keeping militias under state control, and preventing them from turning on each other, is a major test for the Iraqi government as it slowly claws back territory from the Islamist militants.

As the fighting escalated Sunday, with both Kurds and Shiite militias sending reinforcements to the town, Iraqi Prime Minister Haider al-Abadi ordered the army to "take all necessary measures to control the situation." Leaders from all sides were contacted to "defuse the crisis" and focus efforts against the common threat of the Islamic State, a statement from his office said.

The area, home to a mix of Arabs, Kurds, and Turkmen - and both Sunnis and Shiites - is not new to clashes. Fighting also broke out between Shiite Turkmen and Kurdish forces in November last year, until a cease-fire was reached between local leaders. Since then, some residents have erected concrete walls to divide their neighborhoods.

Turkmen fighters with Iraqi Shiite militias claimed to have burned two tanks belonging to the Kurdish forces during the clashes Sunday. A Kurdish commander, Col. Azad Serwan, was also killed, both sides confirmed.

At least 10 fighters and two civilians were killed, Reuters reported. Shiite militias accused Kurdish forces of blocking them from being able to transport their casualties to a hospital.

Heavy shelling hit residential neighborhoods of the city, said Mohammed Ahmed, a 28-year-old resident, speaking by phone, with the crack of gunfire audible behind him.

The town has become a "second Kashmir" said Turkmen member of parliament Niazi Oghlo, referring to disputed territory between Pakistan and India.

Hadi al-Amiri, the leader of Iraq's Badr Organization, one of Iraq's most powerful Shiite militias, arrived in nearby Kirkuk to negotiate a resolution with Kurdish commanders.

"All sides have agreed to stop hostilities immediately," said Kirkuk's Kurdish governor, Najmaldin Karim. He said there would be a subsequent meeting to work out a longer term solution, but he said he thought that armed groups that are not official state forces should not be allowed inside towns and cities.