“We’re saying it has to be a cease-fire, and they didn’t want to do a cease-fire,” Mr. Trump said of the Afghan insurgents. “Now they do want to do a cease-fire. I believe it’ll probably work out that way.”

Mr. Ghani later joined Mr. Trump onstage for remarks to several hundred American soldiers gathered in an aircraft hanger. The appearance of a foreign leader before American troops was unusual. Mr. Ghani, giving an energetic, almost campaign-style speech, praised Mr. Trump as “the architect” of a strategy for “wiping out Al Qaeda” in Afghanistan, and hailed him for the killing is ISIS leader Abu Bakr al-Baghdadi.

He arrived in Afghanistan one day after at least 13 people were killed when their car struck a roadside bomb on the way to a wedding party in Taliban-controlled territory northern Afghanistan, officials said. Most of the victims were related to each other.

Peace negotiations with the Taliban have stalled after gaining traction earlier this year and seemed close to an agreement in late summer expected to reduce the American military presence, which numbers from 12,000 to 13,000 troops, by several thousand.

The talks collapsed in stunning fashion on Sept. 7, after Mr. Trump disclosed via Twitter that he was quashing plans for a dramatic meeting at his Camp David presidential retreat with Taliban leaders and Afghan government officials. Angrily citing a Taliban attack in Kabul which killed an American soldier as the plans were coming together, Mr. Trump called off the discussions entirely.

But administration officials say Mr. Trump remains eager to bring an end to the American role in Afghanistan, which costs billions of dollars each year and continues to claim American lives. Earlier this month, Mr. Trump visited Dover Air Force Base in Maryland to pay his respects during the return of two Americans killed in a Nov. 20 helicopter crash in Afghanistan.

Mr. Trump is also searching for foreign policy achievements he can celebrate on the campaign trail over the next year. Several of his other marquee initiatives, including nuclear talks with North Korea and an effort to squeeze concessions out of Iran with economic pressure, have yielded few results.