The United States' decision to involve its military so heavily in the Middle East has been driven by the underlying motive of countering Iran since the U.S. lost complete control of the country following its 1979 revolution. Not long after the revolution, the U.S. backed Saddam Hussein's invasion of Iran in a brutal eight-year conflict that nearly killed off an entire generation of Iranians. The U.S. also secretly armed Iran, which is unsurprising considering the U.S. has a habit of maximizing chaos in the region.
Even though Saddam Hussein was using chemical weapons against Iranians, the U.S. turned a blind eye. In the years following the Iran-Iraq war, America's focus then turned mainly to Iraq after the U.S. government decided to betray its Iraqi ally, launching an invasion into Iraqi territory. The U.S. then slapped sanctions on Iraq, which the U.N. estimates resulted in the deaths of approximately 1.7 million people, including 500,000 to 600,000 children. These democracy-spreading American politicians were well aware of these figures and still thought the price was "worth it."
When the U.S. invaded Iraq again in 2003 and overthrew Saddam Hussein, the establishment's focus immediately shifted back to Iran. Bush stated in 2007 that he had authorized his military commanders in Iraq to "confront Tehran's murderous activities." He also famously claimed it was in everyone's interest "that there be a stable Iran, an Iran that is capable of rejecting Iranian influence."
"I mean Iraq," he added, correcting himself.
Bush's incessant gaffing may be laughable in that he confused Iran with Iraq when he was clearly referring to one as a newly formed ally and one as a long-term rival, but even if he had spoken correctly, the statement would still have been somewhat laughable. Some years later, Iran is one of Iraq's closest allies and has been integral in ousting ISIS from Iraq's major cities. Iranian-backed militias were even drawn into the recent chaotic fight in Mosul – a U.S.-backed operation – and were also major players in other strategic areas, like Fallujah.
Iran has firmly supplanted itself into Iraq and doesn't appear to be leaving anytime soon – unless the U.S. is willing to drive them out physically.
So how did Iran get so involved in Iraq? To put it simply, the U.S. ousted a Sunni Iraqi leader they had backed to wage a brutal war against Iran and replaced him with a government that was majority-Shia — meaning the new government was capable of aligning itself with Tehran. If the U.S. wanted to truly isolate Iran, they should never have removed the most anti-Iranian president the Bush administration could ever have hoped for, let alone replaced him with a Shia-dominated government in their effort to destroy as much of Hussein's legacy and support base as possible.