Last year, Congress appropriated $3.6 billion to train and equip Iraqi security forces, with a priority on units under Mr. Araji’s Interior Ministry. They include border guards monitoring the long Syrian-Iraqi frontier, a place where American and Iraqi commanders fear that Islamic State remnants could regroup, and which Iran sees as part of its corridor to move fighters and weapons to Syria and Lebanon. The funds also equip the Iraqi SWAT teams responsible for arresting and detaining terrorism suspects, and train a national police force in charge of daily security.

It was the Islamic State’s conquest of a third of Iraqi territory in 2014 that first brought together once-rival Iraqi militias and security forces with an American-led military coalition in a united effort to defeat a common enemy. The United States wanted to prevent the Islamic State from building a caliphate in Iraq and Syria, and the Shiite militias saw the Sunni extremist group as a sectarian threat.

After Iraq’s regular armed forces crumbled in the face of the Islamic State blitz, a coalition of Iranian-financed Shiite militias took up front-line positions against the extremists. The militias never worked directly with the Americans, but a joint command helped coordinate their efforts to defeat the Islamic State.

Now, some of the most influential militia leaders are working directly with the Americans and pressing for a continued American military presence.

For some of these former militants, America’s display of superior equipment and skills side by side with them in battle brought a newfound respect. Others say they had an ideological reckoning, a realization that years of sectarianism and interference from Iraq’s neighbors had made their nation vulnerable to invasion. Partnering with the world’s superpower, they said, was the best way to bring Iraq back up from its knees.

“We all made mistakes in the past, the Americans, as well as us,” said Hadi al-Ameri, the leader of the Badr Organization, the largest of the Shiite militias that helped battle the Islamic State and the leader of the electoral alliance of former militia members, known as Fatah. “Now, we need their help. We can’t let our country become a playground for other powers and their agendas.”