Four years ago, al-Qaeda appeared to have been destroyed in Iraq. Last week, fighters from the group captured Fallujah, a city where hundreds of Americans were killed or wounded in the last decade fighting the jihadists. How did this stunning reversal of fortune happen?

Like everything else about Iraq, this is a tragic and confusing story. But two points seem clear: First, the Obama administration, in its rush to leave the country, allowed the sectarian Shiite government of Prime Minister Nouri al-Maliki to undo many of the gains made against al-Qaeda. Second, Iran has waged a brilliant covert-action campaign that turned Maliki and Iraq into virtual clients of Tehran — and in the process alienated Sunnis and pushed them toward extremism.

“What is tragic is that Iraq’s slide toward an Iranian axis and civil war were not only predictable but indeed predicted by Iraq experts within the U.S. government,” laments one former U.S. official. “Iraq’s current meltdown and its grave implications on U.S. national security interests were entirely avoidable.”

The greatest irony of all is that Iraqis voted in March 2010 to dump Maliki in favor of an alternative slate headed by Ayad Allawi, a pro-American former interim prime minister. In the horse-trading that followed, however, Maliki and his Iranian sponsors (bizarrely backed by the United States ) ended up forming a new government, with Vice President Joe Biden, the architect of U.S. policy (if that’s the right word), proclaiming all the while that “politics has broken out in Iraq.”

Maliki’s new government has played a particularly vengeful sort of politics. The government reneged on promises to pay the Sunni tribal militia that Gen. David Petraeus mobilized in 2007 and 2008 to battle al-Qaeda in Fallujah and other areas of Anbar province. Many Sunnis, fearing that Maliki’s Shiite government was simply a tool of Iran, began turning back toward sectarian warfare.

1 of 33 Full Screen Autoplay Close Skip Ad × Tom Toles on revolution in the Middle East View Photos Toles’s take on the situation in Libya, Egypt and beyond. Caption Toles’s take on the situation in Libya, Egypt and beyond. Buy Photo Wait 1 second to continue.

The covert campaign in Iraq was directed by Qassem Suleimani, the head of the Quds Force of the Iranian Revolutionary Guard Corps (IRGC), and it included a range of different Shiite figures around Maliki. This ability to ride many horses at once is a mark of Suleimani’s operating style. The Iranians also benefit from intelligence relationships that in some cases date back 40 years.

Iran has drawn its cards from a full deck of Iraqi militias. Abu Mahdi al-Muhandis, who allegedly helped plan the 1983 attack on the U.S. Embassy in Kuwait, now directs the IRGC-backed insurgent group known as Kataib Hezbollah. Qais al-Khazali, charged with kidnapping and killing U.S. Marines in Karbala in 2007, runs an IRGC-allied insurgent group known as Asaib al-Haq, or the League of the Righteous. A third Iraqi Shiite militia is known as the Promised Day Brigades. At Iran’s covert direction, fighters from all three militias have been sent to Syria to battle Sunni rebels there.

Iran allegedly has been able to use Iraq as a staging ground for operations to support Syrian President Bashar al-Assad thanks partly to Hadi al-Ameri, the Iraqi minister of transportation. He headed the Badr Brigade, a pro-Iranian militia.

The sectarian cleavage in Iraq has widened since the United States departed. With Iraqi Shiites pulled toward Iran, Sunnis were drawn back toward the jihadist orbit — especially after Syria lurched into civil war. Al-Qaeda fighters relentlessly moved across the porous border and last year proclaimed themselves the Islamic State of Iraq and Syria. This new jihadist magnet has drawn about 10,000 foreign fighters, many with European passports.

Al-Qaeda’s resurgence in Anbar has been chilling. Last week, hundreds of fighters, traveling in about 75 armed trucks, surged into Ramadi and took over police and gas stations there. Ramadi was largely cleared this week, thanks to Sunni tribal fighters. Fallujah will be harder to liberate. Maliki has heeded American advice not to allow the Iraqi army to storm the city, which would alienate the Sunni residents. Meanwhile, the Iraqi parliament has voted to put Sunni tribal fighters back on the payroll . But, tragically, a new war to drive al-Qaeda from the Euphrates Valley is beginning, just a few years after the terrorist group appeared to have been crushed there.

New Iraqi elections will be held in April. It’s a mark of Iran’s tactical skill that Tehran is said to be abandoning Maliki and searching for a new client. The United States is picking up the slack, once more supplying Maliki with advice and weapons. The Iranians, it must be said, play the Iraqi game with a finesse and staying power the United States has never matched.

Read more from David Ignatius’s archive, follow him on Twitter or subscribe to his updates on Facebook.