Iraq is not Afghanistan, it had similar conditions to Iran and ended up a disaster. In fact, can you name even one thriving democracy in the Middle East? Except Israel of course, which has history and culture that is very different for that region.
As much as I can tell, Iraq as a powerful independent state was destroyed by Mongols in 1300s, and never restored.
Since then, Iraq was controlled by various foreign powers, as a colony: partly Persian, partly Ottoman / Turkish; since late 19th century, it was increasingly under British control, and since 1970s, under Saddam Hussein: independent but rather undemocratic.
Iran was independent and powerful since 1500s, and it even converted the previous waves of invaders to its culture (somehow similar how the Manchu invaders gradually converted to the Chinese culture). While obviously not democratic, Iran was not a cultural backwater, up until the Islamic revolution in 1979. Even under the power of ayatollahs Iran's urban societies feature strong citizen movements demanding more liberty and equality, e.g. women equality: women had much more rights under the last Shah regime, and people remember that.
In general, I suppose that Iran, had the current theocratic regime been overthrown, would not turn into a failed state, much like Russia hasn't become a failed state after the Communist regime fell. (Regarding perspectives of EU / US-style liberal democracy there, I'm much less certain, though chances are.)