But the evolving alliance means that the United States military is taking a risk: training, sharing intelligence and planning missions with former members of Iranian-backed militias that once fought and killed Americans.
Several former militia commanders have risen to high-level political positions. Now, a coalition of them is expected to be among the biggest winners in parliamentary elections this Saturday, giving them even more prominent roles in the new government and possibly determining the future of the American presence in Iraq.
The United States has expanded secretive military ventures and counterterrorism missions in remote corners of the world, but in Iraq it is taking a different tack. Here, the United States is reducing its troop presence and gambling that common interests with former adversaries will help prevent a resurgence of the Islamic State. The bet seemed to pay off with the announcement this week that a joint Iraqi-American intelligence sting captured five senior Islamic State leaders.