When President Obama declared an end to the Iraq war, he also looked forward to “a new phase in relations between Iraq and the United States.” If we play our cards right, this new phase may prove more important than the withdrawal of U.S. troops.

Critics charge that the withdrawal is a defeat for the United State and a victory for Iran, and leaves Iraq vulnerable to a rekindled civil war. They could not be more wrong.

I have worked on Iraq policy for nearly eight years. I was an early advocate for a surge that sent 30,000 troops to Iraq — then I helped negotiate the 2008 accords that set the terms for withdrawal of all U.S. forces by the end of this year. Most recently, I helped manage talks with the Iraqis on whether and how to extend that deadline.

The decision to complete our withdrawal was not the result of a failed negotiation but rather the byproduct of an independent Iraq that has an open political system and a 325-member parliament, whose proceedings are televised daily. U.S. and Iraqi legal experts determined that any new accord required parliamentary approval to ensure U.S. troops would be immune from Iraqi laws. No bloc in parliament other than the Kurds supported that requirement.

Consequently, our trying to force an agreement through the Iraqi parliament would have been self-destructive. That had nothing to do with Iran and everything to do with Iraqi pride, history and nationalism. Even the most staunchly anti-Iranian Iraqi officials refused to publicly back a residual U.S. force — and in the end, they supported our withdrawal.

To be sure, Iran retains great influence in Baghdad. But so do we. Over the course of our talks this summer, the Iraqi government quietly dismantled Iranian-backed militia groups in Maysan province, on the Iranian border. It sent messages to Tehran that any attack on U.S. forces would be considered an attack on the Iraqi state. It completed the purchase of 18 F-16s, becoming the world’s ninth-largest purchaser of U.S. military equipment — and the fourth-largest in the region behind Israel, Egypt and Saudi Arabia. These are the building blocks of a real defense partnership, and they do not require the basing of U.S. troops.

In addition, and against the heavy lobbying of Tehran, Iraq invited international oil firms to help develop its infrastructure. The oil is now flowing. Daily production is about to top 3 million barrels for the first time in decades. Within two years, Iraq is projected to surpass Iran’s daily exports — and within five years to double its total production.

The argument that we should keep troops in Iraq to balance Iran never resonated with Iraqis, most of whom do not wish to be drawn into a conflict between the United States and Iran. Nor was it clear that a small residual force would have deterred Iran. It may well have had the opposite effect: fueling recruitment to Iranian-backed extremist groups.

What about security? Iraq is averaging between zero and seven security incidents a day nationwide — compared with 180 per day four years ago. After U.S. troops left Iraqi cities in June 2009, security improved. That withdrawal strengthened Iraqi forces and dented the legitimacy of extremist groups fighting U.S. and Iraqi troops. Today, Iraqis are exclusively managing their own security. The full withdrawal may increase risks in the short term, but there would have been serious risks in trying to force the Iraqis to let us stay — including a failed vote in parliament and a long-term breakdown in relations.

Iraq is beset with problems — including a low-grade insurgency and a stagnant political system. Those problems will continue. But active U.S. diplomacy — not basing U.S. troops in Iraq — is essential to helping the Iraqis manage them.

Going forward, the Iraqis have asked for renewed U.S. focus on the Strategic Framework Agreement (SFA), which passed in 2008 and envisions broad ties in the areas of education, commerce and security. In the security field alone, the SFA offers a basis for joint exercises, counterterrorism cooperation and air and naval defense. The withdrawal, thus, is not an end to military cooperation, and it may allow the United States to deepen relationships with Iraqi forces. Similarly, in the fields of trade and education, the SFA can help integrate Iraq further into the global economy.

Making clear that the withdrawal closes one book but opens another is now the essential task for the United States. An entire generation of Iraqis knows little of the United States beyond what they call the American war. Twenty-five percent of the country’s population — nearly 8 million Iraqis — were born after the 2003 invasion. Nearly half the population is younger than 19.

This new generation will soon see U.S. troops leave under an agreement signed by one U.S. president and implemented by another. It will be an honorable end to the war and one of the first of its kind in history. With a serious and renewed focus on the SFA, it can also be the start of a new and lasting partnership between our two countries.

Brett McGurk has served on the national security staffs of Presidents George W. Bush and Barack Obama and as a senior adviser to three U.S. ambassadors in Baghdad.

More from PostOpinions

Krauthammer: Who lost Iraq?

Ray Takeyh: Iran’s waning influence on Iraq

Gerson: The problem is mobility, not equality

Will: Diversity stifling students’ rights