Emma Sky is the director of Yale World Fellows and the author of "The Unraveling: High Hopes and Missed Opportunities in Iraq." She served in Iraq from 2003 to 2004 as the governorate coordinator of Kirkuk, and from 2007 to 2010 as political adviser to Gen. Raymond T. Odierno, the commanding general of U.S. Forces in Iraq. The views expressed are her own.

(CNN) Addressing the nation from the Oval office on Sunday night, President Barack Obama outlined the current U.S. approach to fighting the Islamic State of Iraq and Syria (ISIS). Obama stated that we have been at war with Islamist terrorists since 9/11. However, the number of terrorists has proliferated since then in large part as the unintended consequences of policies the United States has pursued.

Now, as the debate intensifies over how to respond to the group in the wake of the Paris attacks and the shootings in San Bernardino -- and what kind of forces the U.S. and its allies should commit to the fight -- it is worth looking at what led to the emergence of ISIS.

The truth is, of course, that we should never have invaded Iraq in 2003. Yet nothing that happened in Iraq after 2003 was inevitable or preordained -- numerous opportunities were missed to build a better future for the country after the invasion took place.

The collapse of the state (through the Debaathification of the armed forces and the dissolving of the country's security institutions) undoubtedly led to Iraq's descent into sectarian war and created the chaotic space for the emergence of al Qaeda in Iraq. Yet even after these colossal mistakes at the beginning of the Iraq war, the United States still succeeded in midwifing the emergence of an inclusive political order from 2007-2009.

So, as recently as six years ago, few could have envisaged that the Islamic State would rise up out of the ashes of al Qaeda in Iraq and take control of a third of Iraq. Iraq had emerged from its civil war, Sunni tribes (with the support of U.S. forces during the so-called surge) had defeated al Qaeda in Iraq, and there was optimism that the country was headed in the right direction.

What went wrong?

The turnout for the 2010 elections was high. Polls showed belief in the political process and optimism that the country was moving beyond the sectarianism that had bedeviled it.

Iraqiyya, a coalition led by Ayad Allawi (a secular Shia), campaigned on a platform of "no to sectarianism," and " Iraq for all Iraqis ." It attracted support from Iraq's Sunnis, secular Shia, and minorities. And it won the most seats in the elections.

However, Prime Minister Nuri al-Maliki refused to accept the election results. He called for a recount and used Debaathification to try to disqualify Iraqiyya candidates and to annul their votes. When that failed to give him victory, he further intimidated his rivals and pressured the judiciary, underscoring his determination to remain in power.

There were differences within the U.S. system over what to do. Senior military officers who had served multiple tours in Iraq, along with diplomats with Middle East expertise, argued that the United States should uphold the right of the winning bloc, Iraqiyya, to have first go at forming the government in the belief that this could lead to power-sharing between Allawi and al-Maliki, or the selection of a third person to be prime minister. However, Vice President Joe Biden decided that the United States should support the incumbent , al-Maliki, for a second term as prime minister, apparently believing that he was a friend of the United States, an Iraqi nationalist, and someone who would give us a follow-on security agreement to keep some U.S. forces in Iraq post 2011.

However, despite U.S. pressure, Iraqiyya adamantly refused to countenance a second al-Maliki term. After all, Iraqi politicians had spent the previous two years trying to remove al-Maliki through a vote of no confidence in parliament, fearful that he was turning into a dictator. It should have been no surprise they would not back him now.

Iran, in the meantime, sensed an opportunity to outmaneuver the United States by using its influence to ensure a second al-Maliki term with the support of his arch-rivals the staunchly anti-American Sadrists -- the condition being that all U.S. forces depart from Iraq by the end of 2011.

In the region, people spoke of how Iran had driven the United States out of Iraq, and how the U.S. had given Iraq to Iran "on a silver platter."

Secure in his seat, al-Maliki accused Sunni politicians of terrorism , and drove them out of the political process. He also reneged on his promises to tribal leaders who had fought against al Qaeda in Iraq, arrested Sunnis en masse, and subverted the democratic institutions that were supposed to keep a check on his power. Sunni protests were violently crushed . All the while, the White House kept silent.

It was clear to anyone who followed Iraq closely that politics were breaking down -- not "breaking out" as a White House official claimed -- as al-Maliki became increasingly authoritarian and moved closer to Iran. Furthermore, the capacity and willingness of Iraqi society to contain al Qaeda in Iraq was being eroded through the assassination, detention and flight of Sunni Awakening leaders, as well as the increasing politicization of the Iraqi security forces as al-Maliki replaced leaders who he suspected of being close to the United States with ones personally loyal to him.

Yet when al-Maliki visited the White House in November 2013, President Obama publicly welcomed him, saying : "We honor the lives that were lost, both American and Iraqi, to bring about a functioning democracy in a country that previously had been ruled by a vicious dictator. And we appreciate Prime Minister Maliki's commitment to honoring that sacrifice by ensuring a strong, prosperous, inclusive and democratic Iraq."

Within months of that visit, ISIS had taken control of a third of Iraq and the Iraqi army had collapsed.

Ultimately, had the Obama administration not insisted on supporting al-Maliki -- and ignoring his ruinous policies -- then the inclusive political order that the United States had nurtured through the surge might not have broken down -- and the resurrection of ISIS might have been prevented.

We must learn from our past mistakes if we are to stem the proliferation of terrorism -- and help set the conditions for ISIS to be defeated both militarily and ideologically.