The militia blamed the US-led coalition for the assault but the Islamic State group claimed its fighters had targeted the militiamen.
The deputy head of the militia, known as Kattaib Sayeed al-Shuhadaa, accused US forces of carrying out the early Monday assault. The Baghdad-based spokesman of the US-led coalition, Army Col. Ryan Dillon, dismissed the allegation, saying on Twitter that no coalition airstrikes took place in the area at the time.
He said the attack was launched from around Iraq's city of Mosul, recently recaptured by Iraqi forces from the Islamic State group, and was followed by an on-the-ground assault by S militants. Along with 40 killed, at least 30 militiamen were wounded, al-Maksousi added.
The militia vowed "this act will not pass without punishment."
In an online statement, IS said it staged a three-pronged attack that included a suicide bombing, followed by fighters storming the militiamen's positions. The group added that one IS fighter was captured.