BAGHDAD — Iraq’s politicians were struggling to meet the constitutional deadline to form a new government when, in an isolated village, two masked men stepped into a Sunni mosque and opened fire on Friday, killing dozens of worshipers.

Within hours, Sunni leaders said they were pulling out of the negotiations, and the political process was suddenly jammed again by the same sectarian rifts that have long bedeviled this country.

The formation of a new, inclusive government that could command some support from both Sunnis and Shiites is widely seen as a vital first step in confronting jihadists from the Islamic State in Iraq and Syria, who have stormed into Iraq, seizing territory and taking control of major cities in the north and west. President Obama has hailed the appointment of a new prime minister, Haider al-Abadi, and many observers hope that Mr. Abadi will undo the policies of his predecessor, Nuri Kamal al-Maliki, who has been accused of marginalizing Iraq’s Sunni minority and, in effect, opening the way for the advance of the Sunni militant group.

But only a new government can undo those policies, which included the revitalization of Shiite militias, the arrests of many Sunni men, and military strikes on Sunni areas in which civilians were killed.