For weeks, Iraqi Kurdish fighters had joined an unusual alliance to free this dusty highway town besieged by Islamic State fighters. Shiite militias, Iranian trainers and U.S. military pilots had all contributed, finally wresting the city from the Sunni extremists and saving the 15,000 residents from starvation or brutal slayings.

But on Friday, as the Kurdish pesh merga fighters approached the city to greet the residents they helped save, they were treated less like liberators and more like intruders. “Pesh merga forces are not allowed to enter this city!” yelled a Shiite militiaman with Kataib Hezbollah, an Iraqi group. He waved his rifle at them and the pesh merga retreated.

“We fought for three months here, and now we have to fight these bastards,” said one of the pesh merga, who regard this area as part of their territory. “If this continues, we’ll have another war.”

“They are just like animals,” said a second pesh merga fighter. “They are mules.”

The Obama administration’s strategy in Iraq is predicated on the country’s competing militia groups, as well as its battered army, setting aside their differences over territory, ethnicity and religion to form a grand coalition to battle the radical Sunni members of Islamic State. The aftermath of the fighting in Amerli shows how quickly this hodgepodge of militia forces can turn on each other as they fight for influence and the spoils of battle.

Suspected massacres by the Islamic State

The road to Amerli also offers a glimpse of how the last few months of fighting have destroyed virtually every vestige of the Iraqi state in the north. After being turned away from Amerli, the pesh merga fighters returned to their base, just three miles away, passing through a half-dozen other Shiite militia checkpoints. Some belonged to the Badr Brigades, others to Saraya al-Salam and Asaib Ahl al-Haq. All were vying for influence in the area. Each flew their own militia flag; the Iraqi flag was nowhere to be seen.

The fractured landscape offered one sign after another of how difficult it would be for northern Iraq to return to the multiethnic, religiously mixed society it had once been.

Mass graves along the road

On the side of the road near Amerli, lined up in a row, were the bodies of about a dozen Shiite men killed in June during the first wave of assaults by Islamic State insurgents in the area. The extremists killed hundreds of Shiites and members of ethnic minorities during their sweep through northern and western Iraq. Thousands more residents fled.

With the Islamic State fighters gone, it was finally safe for the local residents to exhume the mass graves. Friends and family members bent over the corpses searching for something — an identification card, a cellphone or a scrap of familiar clothing — that might identify their loved ones.

Ibrahim Kalif spotted what looked like a familiar T-shirt of his friend, a truck driver who regularly hauled bags of cement down the highway toward Baghdad. “I have seen him wearing these clothes,” Kalif said. “I’m sure it is him.”

A second mass grave, consisting of about 24 more bodies, was uncovered nearby, said a member of parliament from the area. Like Kalif’s friend, most of the dead were truck drivers, who were stopped by Islamic State fighters and killed.

On this day, Kalif was more interested in grieving for his lost friend than revenge. “We just want to live in peace,” he said, covering his nose with his sleeve to ward off the stomach-wrenching smell.

An abandoned city

A few hundred yards away was the Sunni village of Suleiman Beg, once home to about 10,000 people and now completely abandoned. A handful of Shiite militia fighters ducked into the homes that had not been reduced to rubble in the fighting, looking for televisions, bicycles or jewelry they could steal. The pesh merga fighters posed for pictures in front of the building where the Islamic State fighters beheaded those accused of being spies or criminals. An unexploded artillery shell lay nose-down in what had been a carefully tended garden.

No one had any idea what would happen to the empty city. The pesh merga and Shiite militia fighters agreed that Sunni Arabs couldn’t be trusted to return. “If they come back, they will just plant bombs on the road,” said Capt. Wushar Harki, a pesh merga officer. “I would say that 90 percent of them are terrorists.”

Unfriendly rivalries

The U.S. government has largely looked at the Kurds, who live in a semi-autonomous zone in northern Iraq, as a stabilizing force in the region. But the months of fighting are wearing on the pesh merga troops, who have begun to view everyone with distrust. The pesh merga forces — which are divided into two groups that report to the two major Kurdish parties — even suspect each other. Around Amerli, the pesh merga fighters complain that the best weapons from the U.S. government and Iran are going to Kurdish fighters associated with their rival party.

“We have not seen a single American bullet,” said Maj. Ahmed Mahmoud, the pesh merga commander near Amerli and Suleiman Beg.

The Sunnis and Shiites, meanwhile, say the Kurds are using the chaos to grab territory well beyond the Kurdistan region’s traditional borders with an eye to independence.

Amerli had seemed to represent the possibility of an alliance of different ethnic groups and formal militaries to defeat the extremists. The city is inhabited by thousands of Iraqi Turkmens, most of them Shiites who are of Turkic heritage, rather than Arab, like the majority of Iraqis.

The partnership between Iraqi troops, Shiite militias and Kurdish fighters — supported by U.S. airstrikes and NATO humanitarian air drops — would prove short lived.

Once he returned to his base, Harki was still angry about the Shiite militia forces that had denied him and the other pesh merga forces entry to Amerli. “That land belongs to the Kurdish people,” he said. “But right now, it is inhabited by others.”