At least 70 people have been killed after Shia Muslim militia opened fired inside an Iraqi Sunni mosque in the country's eastern Diyala province, an Iraqi security source said.

The attack on the mosque, which also wounded 20 people, was apparently carried out in revenge for the killing of militiamen in either clashes or a roadside bombing in the area.

Such sectarian violence could hurt efforts by Iraq's new prime minister, moderate Shia Haider al-Abadi, to form a government that can unite Iraqis against Islamic State, the Sunni militants who have seized large parts of the country.

Ambulances transported the bodies to Baquba, the main city in Diyala province, where Iranian-trained Shia militias are powerful and act with impunity.

Attacks on mosques are acutely sensitive and have in the past unleashed a deadly series of revenge killings and counter attacks in Iraq, where violence has returned to the levels of 2006-2007, the peak of a sectarian civil war.

Iraqi Shia militia forces executed 15 Sunni Muslims and then hung them from electricity poles in a public square in Baquba in July, police said.

Diyala police officials told Reuters they had provided Shia militias with names for hit lists so that suspected members of Islamic State could be tracked and executed.