Gunmen attacked a Sunni mosque during Friday prayers and killed at least 64 people, prompting Sunni lawmakers to withdraw from talks on forming a new, more inclusive government capable of confronting the Islamic extremists who have overrun large swaths of Iraq.

It was not immediately clear if the attack was carried out by Shia militiamen or extremists of the Islamic State of Iraq and Syria (ISIS), who have been advancing into mixed Sunni-Shia areas in volatile Diyala province and have been known to kill fellow Sunni Muslims who refuse to submit to their harsh interpretation of Islamic law.

However, Sunni lawmakers quickly blamed the carnage on powerful Shia militias out to avenge an earlier bombing, and two major Sunni parliamentary blocs pulled out of talks on forming a new Cabinet. The move creates a major hurdle for prime minister-designate Haider al-Abadi as he struggles to reach out to disaffected Sunnis to form a government that can confront the ISIS extremists.

Both al-Abadi and outgoing Prime Minister Nouri al-Maliki condemned the attack and called for an investigation.

Iraq security

A policeman checks a man for weapons before he attends prayers at a Sunni mosque in Iraq. (Ahmed Saad/Reuters)

The onslaught on the Musab bin Omair Mosque in the village of Imam Wais began with a suicide bombing near its entrance, followed by a raid by gunmen who stormed the building, opening fire on worshippers, security officials said.

Iraqi security forces and Shia militiamen raced to the scene to reinforce security but stumbled on bombs planted by the militants, which allowed the gunmen to flee, according to officials in Imam Wais, 120 kilometres northeast of Baghdad.

At least 64 people were killed, including four Shia militiamen, and more than 60 people were wounded, according to medical officials. All officials spoke on condition of anonymity because they were not authorized to brief the media.

In pointing the finger at Islamic State fighters, village officials said the Sunni extremists have been pressuring two prominent Sunni tribes in the area — the Oal-Waisi and al-Jabour — to join them, but so far they have refused.

However, local Sunni lawmakers in Diyala province blamed Shia militiamen for what they said was a revenge attack for a bombing earlier Friday.

Kurdish Peshmerga troops

Kurdish troops move down a street during an intensive security deployment after clashes with militants of the Islamic State in Jalawla, Iraq. (Reuters)

In that attack, a roadside bomb hit the convoy of a local Shia militia leader, wounding three of his bodyguards, Sunni lawmaker Raad al-Dahlaki said. He said the militia leader survived, and out for revenge, entered the mosque along with fellow Shia gunmen and opened fire.

Shia militias then surrounded the general hospital in Baqouba, Diyala's provincial capital, vowing to attack relatives of the dead, al-Dahlaki said.

In announcing their pullout from talks on forming a new government, Sunni parliamentary blocs affiliated with Parliament Speaker Salim al-Jabouri and Deputy Prime Minister Saleh Al-Mutlak demanded that the main Shia parliamentary bloc hand over the perpetrators within 48 hours and compensate the families of victims "if they want the political process and the new government to see the light of day."

White House urges uniting against extremists

The Obama administration condemned Friday's "vicious attack," and said it underscores "the urgent need for Iraqi leaders from across the political spectrum to take the necessary steps that will help unify the country against all violent extremist groups," State Department deputy spokeswoman Marie Harf said.

U.S. Vice President Joe Biden later said the U.S. is prepared to help Iraq pursue a federal system that would decentralize power away from Baghdad.

In an opinion piece in The Washington Post, Biden says Iraq is making progress in forming a new government. But he says sectarian divisions are fuelling extremist movements like ISIS.

If the mosque attack proves to have been carried out by Shia militiamen it would deal a major blow to al-Abadi's efforts to reach out to the country's Sunni minority, whose grievances are seen as fuelling the Islamic State insurgency.

Since early this year, Iraq has faced an onslaught by the Islamic State group and allied Sunni militants. The crisis has worsened since June, when the group seized Iraq's second-largest city of Mosul and subsequently declared an Islamic state, or caliphate in territory under its control.

In Diyala, Islamic State fighters have clashed with Kurdish forces guarding disputed territory claimed by the Kurdish regional government in the north. The extremist group pushed Kurdish forces out of the town of Jalula earlier this month after heavy fighting.

At the height of Iraq's sectarian bloodletting in 2006-2007 the province was among the country's most lethal areas.

On Friday Iraq's top Shia cleric again called upon the country's leaders to settle their differences in a "realistic and doable" manner and swiftly form a new government to confront the Sunni insurgency.

Grand Ayatollah Ali al-Sistani said the next government should be made up of candidates who care about "the country's future and its citizens" regardless of their ethnic and religious affiliations.

The reclusive cleric's remarks were relayed by his representative, Abdul-Mahdi al-Karbalaie, during Friday prayers in the Shia holy city of Karbala.

Mosul Dam conflict continues

Al-Karbalaie also called for urgent aid to be airlifted to residents of a small Shia town which has been besieged by Sunni militants in northern Iraq.

About 15,000 Shia Turkmen in the town of Amirli have been under a tight siege and are running out of food and medical supplies. The town is located about 170 kilometres north of Baghdad.

The United States launched airstrikes this month to support Iraqi and Kurdish forces looking to reclaim territory seized by the Islamic State group.

U.S. Central Command said Friday that it conducted three new airstrikes around the Mosul Dam, where clashes with militants continue nearly a week after Iraqi and Kurdish forces retook the sprawling facility with U.S. air support.

Since Aug. 8, the U.S. has launched a total of 93 airstrikes, of which 60 were near the Mosul Dam.