That deal, criticized by Afghan officials for lacking measures that would ensure stability, would include a timeline of about 16 months for a gradual withdrawal of the remaining 14,000 American troops, with about 5,000 of them leaving in 135 days after its signing. In return, the Taliban would provide counterterrorism assurances to ease American fears of repeat of attacks on home soil — such as the attacks by Al Qaedaon Sept. 11, 2001, that precipitated the war in Afghanistan.
The final rounds of negotiations — and even Mr. Trump’s invitation for a summit meeting at Camp David — had occurred during a period of intensifying violence, including the killing of American soldiers. In response to the Taliban attacks, the American negotiators had made clear that they were prioritizing the finalization of the agreement, not a boycott of the talks. Their negotiations were also undergirded by increasing battlefield pressure by the American military on the Taliban.
But just how the deal would be announced remained unclear, and competing demands made it even more complicated. Those demands included Mr. Trump’s election promise of ending the Afghan war, the Taliban’s sensitivity about not fracturing their forces, the Afghan government’s need to be seen as having the support of its main ally and sponsor, and Qatar’s wish to get credit for hosting the long-running talks at a time when neighboring countries have ganged up on it in by a blockade.
At the end of August, just as the ninth round of talks was winding down in Doha, the American ambassador arrived at the Afghan presidential palace with the proposal of a Camp David meeting, Afghan officials said. The visit would take place soon after a national security meeting led by Mr. Trump.
Details of the trip to the United States were sorted out between the Afghan president and the American side, when Mr. Khalilzad arrived from Doha and held four rounds of talks with Mr. Ghani. A plane would arrive to take Mr. Ghani and his delegation of about a half-dozen senior officials to the United States.
Mr. Ghani’s ministers knew they would be meeting with their American counterparts and that a Taliban delegation would most likely be arriving, too. But they were unclear on the details of how it would all come together. They had to be prepared on all three issues that were their government’s priority: the presidential elections scheduled for Sept. 28, how the peace talks would move forward to include them and how they would continue to bolster their security forces in a way that would reduce the cost for the United States.
As a sign of how important the event was for the United States, Mr. Ghani got the Americans to agree to include on the trip his national security adviser, Hamdullah Mohib, who had essentially been kept out of the American meetings for months after lashing out at the peace process.