BAGHDAD -- 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 Shiite militiamen or insurgents of the Islamic State group, who have been advancing into mixed Sunni-Shiite 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 Shiite 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 Islamic State extremists.

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

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 Shiite 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, 75 miles (120 kilometres) northeast of Baghdad.

At least 64 people were killed, including four Shiite 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 Shiite militiamen for what they said was a revenge attack for a bombing earlier Friday.

In that attack, a roadside bomb hit the convoy of a local Shiite 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 Shiite gunmen and opened fire.

Shiite 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 Shiite 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."

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.

If the mosque attack proves to have been carried out by Shiite 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 fueling 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 Shiite cleric again called upon the country's leaders to settle their differences 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 Shiite holy city of Karbala.

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

About 15,000 Shiite 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 105 miles 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.

- Associated Press reporter Vivian Salama in Baghdad contributed to this report.