When American officials in Iraq began the slow wind-down of the military mission there, in 2009, some diplomats in Baghdad were cautiously celebrating one achievement: Iran seemed to be on its heels, its influence in the country waning.