BAGRAM AIR FIELD, Afghanistan — President Trump paid an unannounced Thanksgiving visit to American troops in Afghanistan on Thursday and declared that he had reopened peace negotiations with the Taliban less than three months after scuttling talks in hopes of ending 18 years of war.

“The Taliban wants to make a deal, and we’re meeting with them,” Mr. Trump said during a meeting with Afghanistan’s president, Ashraf Ghani, at the main base for American forces north of Kabul.

“We’re going to stay until such time as we have a deal, or we have total victory, and they want to make a deal very badly,” Mr. Trump added even as he reaffirmed his desire to reduce the American military presence to 8,600 troops, down from about 12,000 to 13,000.

Mr. Trump’s sudden announcement on peace talks came at a critical moment in the United States’ long, drawn-out military venture in Afghanistan, a time when the country is mired in turmoil over disputed election results and Americans at home are increasingly tired of an operation that began shortly after the Sept. 11 attacks.