Iraq's prime minister thanked Shiite militias on Monday for helping break a two-month siege by Sunni insurgents on the town of Amirli, a victory speech that showed how the fight against Islamic State extremists is hardening the country's sectarian divisions.