ISIS controls towns to the east and west of Haditha, leaving the city and the troops deployed there virtually surrounded.

The rebels were demanding the turnover of dozens of veterans of the U.S.-sponsored forces—known collectively as the Awakening movement—that successfully repelled al Qaeda fighters in 2007 and 2008, local security sources said.

The mediation in Haditha was taking place only hours after local tribal leaders negotiated the peaceful surrender of the last of the Iraqi soldiers trapped in the oil refinery at Beiji.

The agreement between tribal sheiks and ISIS fighters, reached late Monday, ensured the safe passage of government soldiers from Iraq’s largest oil refinery, which fell under the militants’ control over the weekend, a tribal leader in Beiji said by telephone.

As government troops surrendered their weapons to ISIS and left for the semiautonomous northern Kurdistan region, Sunni militants celebrated at the plant and in the nearby town of Beiji, shooting their rifles into the air and using loudspeakers to proclaim their victory, residents said.

State-run Al Iraqiyya television station, in reports aired Tuesday, continued to insist that the refinery was under the control of Baghdad and would “start to operate again within days.”

At least 1,075 people, many of them civilians, have been killed in the past 2½ weeks during fighting in the provinces of Nineveh, Diyala and Salah Al Din, the U.N. said Tuesday.

Write to Matt Bradley at matt.bradley@wsj.com