MOSUL, Iraq — The Mosul district of Gogjali was captured from the Islamic State group weeks ago. So the commander of Iraqi troops here was alarmed when a surprise attack by militants sparked an hour-long gunbattle with his forces.

None of his men were hurt, but the assault meant IS sleeper cells remained among the mainly Sunni Muslim population.

Using loudspeakers, troops on Thursday called on all adult men to report to the main square. About 400 showed up. Under heavy guard and forbidden from using cell phones, they sat on the ground — clearly anxious they were about to face mass reprisals.

Instead, the commander delivered a speech, demanding information but also seeking reconciliation.

"I am a Shiite, but it's not true what you hear that we are here to fight Sunnis," Col. Munir Abdul-Aziz, a burly man in his 40s, told them. "We are here to save you from the terrorist Daesh which has no religion," he added, using the Arabic acronym for IS.

It was a sign of how, in the campaign to retake Mosul, Iraq's military and politicians are making a concerted effort to bridge the country's bitter Sunni-Shiite divide.

Those tensions helped bring the rise of the Islamic State group and have been further inflamed by the fight against the militants. Unless they are eased, militant violence is unlikely to end.

Sunni bitterness toward the Shiite-led government in Baghdad fueled support for the Islamic State group among the community. The minority community has long complained of discrimination under Shiite domination, and the militants were seen as some as protection against the heavy handedness of security forces and the abuse of the Shiite militias.

That support helped IS take over much of northern and western Iraq, starting in late 2013, through its stunning blitz in the summer of 2014 that captured mainly Sunni Mosul.

In the campaign to retake territory from IS the past year, the tensions have been stoked by abuses committed against Sunnis by government-sanctioned Shiite militias. Sunnis in areas from which IS has been pushed out have reported extrajudicial killings by the militiamen, looting and random destruction of property.

The Shiite militias have existed in Iraq for more than a decade — one sign of how the sectarian rivalry has shaped the country since the 2003 U.S.-led invasion toppled Saddam Hussein's regime.

Saddam's fall opened the door for the Shiite majority to dominate the government, and militias linked to Shiite religious parties arose. Disenfranchised Sunnis filled the ranks of the insurgency, and the result was a sectarian bloodbath by Sunni militants and Shiite militias against each other's communities that reached its height in 2006 and 2007.

The latest generation of Iranian-backed Shiite militias gained considerable power after the military melted down in the face of IS in 2014. The militias have been powerful fighters in the campaigns against the Sunni extremists since.

But the government was adamant in excluding the militiamen from the battle to retake Mosul, the last major Iraqi urban center still held by IS.

The policy has seemed to bring successes.

The Iraqi military and security forces are predominantly Shiite, but Sunnis have a significant presence in the ranks. Reports of excesses against Sunni civilians have been negligible.

Shiite politicians have been trying to reach out, arguing that the brutality of IS rule shows that Iraqis — Shiites, Sunni and Kurds — are better off living together in harmony.

He said only Sunnis proven to have fought with IS would face prosecution. "There will be no collective punishment," he said.

The Sunni-Shiite rivalry is not the only one bedeviling Iraq. There are longtime differences over territory and oil between the Baghdad government and the self-ruled Kurdish region.

It may take more than gestures and rhetoric to convince Sunnis that their marginalization has ended.

"We should not have gone to war against Daesh before settling our differences first," said Sunni lawmaker Thafer al-Any. "But, let us see how things are handled after Daesh is defeated. It is difficult to imagine that Iraq will stay united without a political settlement."

But Sunni do see positive signs, and the fight against IS has brought together fighters from the country's Shiites, Sunnis, Kurds and Christians in a loose alliance.

"The attitude of the army toward us in Mosul was 99 percent positive," said Zoheir Hazem, a Sunni who belongs to Mosul's local council. "The army is doing a good fighting job and humanitarian job."

The approach by Abdul-Aziz and his men in Gogjali was in sharp contrast to the tactics adopted by Shiite militiamen. Many fighting-age Sunni males have suffered beatings, detention or worse at militiamen's hands on the flimsiest evidence of having joined IS.

"We came to give you your freedom, but you must cooperate with us," Abdul-Aziz of the 16th Infantry division told the men of Gogjali on Thursday.

"Tell me who among you is from Daesh? Where did they disappear to?" he demanded sharply. Then he went on to remind them of all the things IS banned them from doing — playing football, smoking, using mobile phones and watching television.

Army soldiers later collected the ID cards of the men and ran their names through a data base of wanted IS fighters. The men ended up waiting for about four hours, at the end of which three suspected IS fighters were arrested.

The Mosul campaign has also seen other signs of unity.

Associated Press reporters visiting the frontlines have often witnessed soldiers sharing their food rations and water with displaced civilians. Wounded civilians have received treatment at military field hospitals. Scenes of civilians welcoming the troops with embraces, kisses or a handshake have been common. One video clip on social media purports to show special forces fighters rescuing children from a raging fire caused by a suicide car bomb.

Earlier this week, an army captain was harshly admonished by a senior officer for firing in the air to disperse hundreds of displaced civilians who rushed trucks loaded with relief food supplies outside Mosul.

The superior officer took away his pistol.

"There are women and children," he screamed at him as the civilians watched. "You don't deserve the uniform you're wearing."

___

Hendawi and Abdul-Zahra reported from Baghdad.

Copyright 2016 by The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.