“If they keep their commitments,” President Barack Obama said on Wednesday, referring to the two remaining contenders for the Presidency of Afghanistan, then the country “will witness the first democratic transfer of power” in its history.

Secretary of State John Kerry forged those commitments last weekend, when he flew in to prevent a coup attempt and succeeded, for now. His dealmaking salvaged the possibility that, almost thirteen years after the United States and its allies installed Hamid Karzai in power, there would be a manageable political transition in Kabul.

What are the odds? Four of the last six rulers of Afghanistan died violently at the hands of successors. Another, Mullah Mohammad Omar, slipped the noose and escaped into exile, where he remains, presumably in Pakistan. The possible “first” President Obama described must be considered against that recent history. The stakes for the United States and Europe are high: if Kerry’s deal collapses, Afghanistan faces the prospect of a sudden and violent civil war, one that would destabilize Pakistan and other neighbors, and renew the country’s attractiveness as a haven for international militants.

Yet there is reason to think that Kerry’s compromise will stick. For more than a year, up until a few weeks ago, Afghanistan’s factional leaders—the United States military prefers to call them “power brokers” these days, not “warlords”—had acted as if they believed that the trouble of a civil war would be considerably greater than the ignominy of sharing power with one another, no matter who won the Presidential election.

On Monday, July 7th, that changed suddenly. A network of northern Tajik governors, former intelligence and defense officials, along with an unknown number of army and police commanders, apparently activated a plan for a coup to install their favored Presidential candidate, Abdullah Abdullah, a former foreign minister. They believed that Abdullah’s opponents had stolen the vote. Their target would have been the presidential palace in Kabul occupied by Hamid Karzai.

There is little doubt the coup makers could have succeeded; they have the lion’s share of Kabul’s guns. The wider war they would have triggered would have turned hard and bloody, however. The northern militias would have found themselves in a conflict not only with the Taliban but also with previously pro-government Pashtuns aligned with Karzai and his favored Presidential candidate, Ashraf Ghani. The progress Afghanistan has made in health, education, life expectancy, communication, and urbanization since 2001 would have crumbled quickly.

At a critical moment, however, apparently late in the night in Washington, President Obama telephoned Abdullah and talked him and his armed backers into standing down. After a shaky few days, during which it was not clear whether Abdullah was in full control of his supporters, Kerry landed in Kabul and opened negotiations.

To address clear evidence of fraud in the second round of Presidential balloting, every vote cast in that round will now be audited under international monitoring. To prevent a revolt after the recount is completed, the candidates have agreed on a power-sharing formula, under which the eventual loser will have the right to become prime minister—a new, powerful position—or to name one of his supporters to the job.

The deal shows what an able Secretary of State can do when the parties to a negotiation for the most part want to find equilibrium. That is not the case in Israel and Syria, where Kerry had earlier struggled with herculean diplomacy, and it is probably not the case in Iraq today, either.

In Afghanistan, however, the incentives for compromise had always looked stronger. Afghanistan is a ward of the international system. It receives billions of dollars in international aid to pay salaries for its security services. Its weak state would not function without outside subsidy. The power brokers behind Abdullah and Ghani all benefit from international support. And the Afghan public around them has a living memory of isolation and perpetual violence, during the civil war of the nineteen-nineties; they would prefer to reclaim the part of their history during the middle of the twentieth century characterized by peaceful independence.

Still, the pressures over the next several weeks will be great. The loser of the vote audit is sure to doubt the result’s authenticity. That suspicion will create fresh pressure on the part of Kerry’s plan that is designed to empower the second-place finisher—and that part of the deal seems worryingly vague and incomplete.

Karzai is scheduled to leave office on August 3rd, but it is not likely that the vote audit will be finished by then. On Afghan social media and in the streets, feelings are running high between Pashtuns and non-Pashtuns, and along other historical fault lines. The country still looks uncomfortably close to the brink.

The question facing what used to be known as the Shura Nizar, or the Northern Alliance, is whether, if Abdullah loses the final count, the alliance can achieve more by compromise than by coup-making. The objective answer is yes, but there will be those of senior rank who will argue otherwise.

The case for a coup, as northern hawks see it, is that by launching an outright war now, the Panjshiri Tajiks and their allies would be free to concentrate on fighting the Taliban without the distractions of managing sometime Taliban sympathizers like Karzai and his cronies. The loss of billions of dollars and high-tech military equipment from the United States might be painful, but Indian, Iranian, and Russian arms and money would eventually fill some of the gap. The Panjshiris have been in this position before, and they and their Tajik and Hazara allies believe deeply that their political claims are legitimate. They are not going to readily sacrifice those claims for short-term American support; it is not clear how long Congress or the White House will keep the financial spigot open, in any event. Many Afghans, therefore, fear that a post-American civil war is only a matter of time; some Panjshiri hawks will make an articulate case for seizing the initiative now, using the allegations of a stolen vote as a basis for lobbying for legitimacy in the world’s eyes.

This line of thinking is dangerously delusional, but it is not quite as delusional as the thinking often present in Hamid Karzai’s palace and his Pashtun circle, which is where the electoral fraud that triggered the present crisis seems to have originated.

Karzai apparently tells interlocutors that the United States and Iran are conspiring to empower northern ethnic groups at his expense and at the expense of Pashtuns more generally. Perhaps he even believes it. But it is an absurd conspiracy theory, considering all the shenanigans the United States has tolerated passively from Karzai and his allies over the past decade.

Reportedly, Karzai and Ghani have indicated privately during the latest crisis that if they rejected Kerry’s deal, defied the United States, and joined up with the Taliban to fight against the Northern Alliance, the Taliban would welcome them as Pashtun nationalist heroes. It has been more commonly assumed that the Taliban would hang them from the nearest post, as traitors to Islam. This is not a hypothesis either Karzai or Ghani would be wise to test. If war comes, a better bet would be an early helicopter to the airport, en route to condominiums in Abu Dhabi.

One recent Afghan ruler who died peacefully in his sleep was King Zahir Shah. He was chased into exile in 1973, but returned in 2002 as the “father of the nation,” as a guest of President Karzai. The aging former king lived his last years on the extended grounds of the presidential palace, as a respected and even revered symbol of Afghan nationalism. He died in 2007 and was mourned at a thronging public funeral.

Hamid Karzai has built a fortified retirement residence of his own in Kabul, near the presidential palace. If Kerry’s deal holds, he may yet live and die there peacefully, acknowledged as a constructive if idiosyncratic architect of national recovery. But if he and his allies—or Abdullah and his allies—miscalculate over the next few weeks, they will return their country, tragically, to the path of ruin.

Above: John Kerry and Abdullah Abdullah shake hands at the joint press conference following their meeting about a power-sharing deal. Photograph by Haroon Sabawoon/Anadolu Agency/Getty.