The agreement to form a unity government in Afghanistan was forged after a pivotal meeting last week in which Secretary of State John F. Kerry warned that failure to reach a deal would put American support for the country at risk.
After three months of trying to bring together Afghan presidential candidates Ashraf Ghani and Abdullah Abdullah, Kerry last Wednesday addressed a meeting of Abdullah's 30-member leadership team through a phone link from the State Department to Kabul.
His message, aimed especially at Abdullah's most militant supporters, was that the deal on the table "was the best deal they were going to get, and that there would be consequences for rejecting it," said a senior administration official, who declined to be identified because he was not authorized to speak publicly.
"I have to emphasize to you that if you do not have an agreement, if you do not move to a unity government, the United States will not be able to support Afghanistan," Kerry told the group, which was seated in a rectangle in a large room.
The agreement, signed Sunday in Kabul, paves the way for Afghanistan's first democratic transition of power.
The transition has been in doubt since a disputed runoff election in June. Since then, a U.S. team led by Kerry has been pressing the two sides to reach an accommodation, amid risks that the standoff could lead to a bloody civil war.
With nearly 30 phone calls and two surprise visit to Kabul since June, Kerry has repeatedly pulled the two sides back from the brink.
A key element of his technique, analysts say, is simply not taking no for an answer -- what some Israeli commentators called "noodge diplomacy" during Kerry's failed effort to broker an Arab-Israeli peace deal.
Kerry's work with the Afghans has come at a time when he was immersed in other frantic diplomacy, including efforts to restrain Russian actions in Ukraine, and a push to try to pull together an international coalition against the Islamic State militant group.
Kerry's call to Abdullah's team on Wednesday came only minutes before he was to appear before the Senate Foreign Relations Committee to explain the administration's strategy for dealing with the militant group.
Kerry argued to Ghani, the vote leader, that he couldn't govern effectively without Abdullah, whose coalition includes ethnic Tajiks and Hazaras. And he argued to Abdullah that he needed to be part of the government to retain influence and avoid a civil war, the senior administration official said.
Kerry also cajoled President Hamid Karzai to remain on board. Though Karzai has been increasingly scornful of the administration, Kerry argued in internal meetings that the president's help was essential to making a deal possible.
Abdullah and Ghani seemed repeatedly to be moving toward a deal, only to then move away from it.
In mid-July, accusations of vote fraud were coming from both sides, and Abdullah's harder line supporters were threatening to set up a parallel government.
President Obama called Abdullah on July 8 and warned that U.S. aid could be cut off unless such threats were halted.
Three days later, at Obama's urging, Kerry took a detour from a planned flight from Beijing to Vienna to stop in Afghanistan. He shuttled between the two camps and Karzai's palace, trying to find areas of agreement.
A month later, Kerry and the two leaders appeared publicly to announce a deal under which the runner-up would take the job of "chief executive." They planned to work out the details so that they could appear together at a planned North Atlantic Treaty Organization summit in early September in Wales.
But differences remained, and behind the scenes, feuding continued. At one point in early September, a member of Abdullah's team warned: "Kabul is our city. We can topple any government," according to a U.S. official involved in the conversation.
Last week, as the negotiations again closed in on a deal, Kerry promised the leaders that the U.S. would take an active role in making sure the unity deal held together.
"The president of the United States is prepared to be a guarantor," he promised.