N o foreign policy decision since America’s retreat into isolationism in the 1930s has done more to harm American and global security than the Iraq war. The invasion and incompetently executed occupation have devastated Iraq and unleashed a civil war that has killed tens of thousands and displaced millions. Iraq has become a recruiting cause and training ground for a new generation of terrorists–young men bent on the suicidal destruction of Americans and Iraqis alike. The balance of power within the Middle East has shifted dramatically in favor of the most radical and extremist elements in the region–led by a newly confident Iran. But what has made the war a blunder of truly historic proportions is that it has cost America the trust of its friends and allies around the world–a trust that since 1945 has been instrumental in translating America’s economic and military power into global influence and leadership.

The overarching challenge confronting the United States after Iraq, therefore, is to restore trust in American leadership. The world needs good reason to once again place its confidence in America’s power, policy, and purposes. That will require broad changes in how Washington conducts foreign policy, especially in its willingness to listen to others and practice what it preaches. But to succeed in rebuilding trust, Washington must first contain the problems that the Iraq war has unleashed: the rising violence inside Iraq, the renewed confidence of a newly ambitious Iran, and the ideological gains made by the jihadist terrorist network. Before we build a new house, we have to put out the fire burning down the old one. If we don’t, whatever rebuilt trust we enjoy elsewhere will be moot in the Middle East: Even a well-behaved Washington that is once again trusted by friends and allies around the world will have trouble attracting followers if the region spirals into greater instability and violence.

The first and most immediate task facing the United States in the Middle East is to minimize bloodshed within Iraq, provide help to those caught in the crossfire, and prevent instability within the country from spilling across its borders. As much as Americans might wish otherwise, the departure of American soldiers and Marines will likely trigger more fighting, at least in the short term. The flame of sectarian and ethnic warfare has been lit. As the sad histories of the Balkans, Afghanistan, Rwanda, and Sudan show, fires like these are difficult to extinguish and often produce staggering death tolls. Trying to prevent that outcome is not only a moral obligation, but a strategic necessity: American interests can only be harmed if we leave behind an Iraq that collapses into the sort of communal violence that wracked Lebanon in the 1980s and Bosnia in the 1990s.

To avoid that nightmare, any U.S. troop withdrawal must be accompanied by a major, Dayton-like effort that would bring all the parties to the table to negotiate a settlement on key political issues: sharing oil revenue, distributing power between the central government and local political entities, and ensuring a monopoly over the means of violence by abolishing militias–within a fixed timetable (say, one month). At the same time, Washington must be prepared to do everything to help Iraqis caught in the full-scale civil war that will ensue should the peace effort fail; American and other international forces still in the country could establish safe havens inside Iraq to provide security, shelter, and safe transit abroad for those who want to leave.

Washington will also need to take steps to keep Iraq’s problems within its borders. Talk that Iraq’s troubles will trigger a regional war is overblown; none of the half-dozen civil wars the Middle East has witnessed over the past half-century led to a regional conflagration. But obvious flashpoints exist. Therefore, Washington will need to maintain substantial troops in northern Iraq to reassure the Turks and deter the Kurds from declaring independence. Elsewhere, the United States will need to use diplomatic tools–as well as the continued presence of troops in the Gulf region–to persuade Iraq’s neighbors to limit their efforts to manipulate the Iraqi civil war to their own ends.

The second challenge the United States faces is to contain Iran’s ambitions and redirect its aspirations. Four years after U.S. troops entered Baghdad, Tehran has emerged the big winner. Saddam Hussein is dead, the limits of American power have been revealed, and Iran’s co-religionists dominate Iraq’s government. It is not surprising, then, that Iran is keen to flex its muscles. The problem is that the government of Mahmoud Ahmadinejad seeks regional domination, intends to acquire nuclear weapons, and supports terrorists.

The Bush Administration’s policy of working with European allies to press for U.N. sanctions against Iran needs to continue. Iran should pay a price for breaking its obligations under the Nuclear Nonproliferation Treaty. But a policy based solely on coercion is guaranteed to fail. Too many countries–led by China and Russia–want economic relations with Tehran for isolation to work. Military strikes are unlikely to end Iran’s nuclear program. They will, however, enrage Iranians, who can easily retaliate against U.S. interests in the region.

As distasteful as it is, then, the United States has to complement its policy of sticks by offering Tehran some substantial carrots. First, there needs to be an unconditional offer to reestablish full diplomatic relations. If the United States could restore diplomatic ties with the Soviet Union 15 years after the October Revolution, it can restore them with Iran 28 years after the Islamic Revolution. Second, Washington should offer to normalize economic ties if Tehran limits its nuclear program and halts support for terrorist groups. Such an offer won’t succeed in buying off Ahmadinejad. Rather, its purpose would be to exploit divisions within Iran and encourage the opposition. The Administration’s open hostility to Iran has enabled Ahmadinejad to deflect domestic criticism of his government’s many missteps and to silence pro-American voices. Supplementing the closed fist with an open hand can help reverse that dynamic.