CAMP ASHRAF, Iraq — At their victory rally, the Shiite militiamen used poetry, song and swagger to sweeten their celebration of an ugly battle.

More than a hundred fighters from the militia, the Badr Organization, had been killed in the farms and villages of Diyala Province in recent fighting against the Sunni extremists of the Islamic State. During the battle, thousands of residents had been forced from their homes — including Sunni families who accused Shiite paramilitary groups like Badr of forced displacement and summary executions.

But the militias had pushed the Islamic State back from key areas in a crucial battle. So last Monday, the Badr Organization convened in a mosque at Camp Ashraf, its base in Diyala, to celebrate its “liberation” of the province — and to serve notice that it was the vanguard force battling the Islamic State, also known as ISIS or ISIL.

Speaking at the rally, to an audience that included giddy fighters barely past their teens, the head of the Badr Organization, Hadi al-Ameri, boasted of the towns his men and allied militias had set free. “These were big operations that others must learn lessons from,” he said.