The president’s announcement was startling for multiple reasons. A surprise summit at Camp David with leaders of an insurgent group that has killed thousands of Americans since the October 2001 invasion of Afghanistan would have been a sensational diplomatic gambit, on par with Mr. Trump’s meetings with the once-reclusive North Korean leader, Kim Jong-un. A senior administration official said the meeting had been planned for Monday, just two days before the anniversary of the Sept. 11, 2001, attacks, which were plotted from Afghanistan and led to the United States’ invasion of the country.

Mr. Trump’s statement also appears to scuttle — for now — his longstanding hope to deliver on a campaign promise to withdraw American troops from an 18-year conflict that he has called an aimless boondoggle.

It comes amid stubborn resistance within Afghanistan’s government about the peace agreement that had been under discussion, not only for security reasons but also because Mr. Ghani has been determined to preserve a planned Sept. 28 election, which he is favored to win. The Taliban have insisted on postponing the election before proceeding with negotiations with the Afghan government.

Several people familiar with the diplomacy between the Trump administration and the Taliban puzzled over Mr. Trump’s stated decision to cancel peace negotiations entirely in response to one American casualty, however tragic. The Taliban had not agreed to halt their attacks on Americans in advance of a formal agreement. That raised the question of whether Mr. Trump might have been looking for a pretext because the talks had run into trouble.

The development is sure to inflame a Washington political debate about the talks that until now had largely played out in national security circles to little public fanfare. Mr. Trump had been coming under growing pressure from conservatives not to hastily exit the country while many leading Democrats have said they support peace talks leading to an American withdrawal.