There seems to be a cold war between the USA and Iran, but they have supported each other in many wars. Why?
The Iranian Revolution was in 1979. Before this time, the US and Iran were close friends when the nation was run by the Shah. The Vietnam War ended in 1975. I assume that Iran supported the US in Vietnam, because the governments were still very close.
The modern Iranian government did not like Sadaam Hussien. The Iran-Iraq War of 1980-1988 was likely fresh on their minds. The US got rid of Saddaam and changed the government to a democracy. Iran didn't just get rid of someone who might attack them, but they can influence Iraq, too as their neighbor for peace and common goals the two nations share.
Most nations supported action in Afghanistan, including several in the Middle East, to prevent spread of the Taliban's aggressive terrorist activities because those could threaten to disrupt society or even topple Middle East governments. Bahrain, Turkey, and the United Arab Emirates still have troops committed to the international war effort.