One outcome is that the administration has expressed a profound eagerness to engage the Taliban in negotiations, with officials saying that there would be no preconditions and that everything, including the future of American and NATO forces, would be up for discussion.

Taliban leaders have said they would talk only to the Americans, without any representative of the Afghan government. Trump administration officials have insisted that Afghan government officials be included.

“Peace must be decided by the Afghans and settled among them,” Mr. Pompeo said Monday.

One decided change from the Obama years is that Mr. Ghani is an eager partner. He showered Mr. Pompeo with praise and expressed thanks to the nearly one million service members “who have for 17 years fought shoulder-to-shoulder with us, and particularly those who have paid the ultimate sacrifice.”

Former President Hamid Karzai of Afghanistan would often complain to, and even insult, American officials, aware that previous administrations felt they could not withdraw troops entirely. But President Trump has sometimes expressed a clear desire to pull out, something he may yet order.

It was Mr. Pompeo’s first visit to Afghanistan as secretary of state. The visit was not announced in advance, and when an Afghan press report announced his arrival, Mr. Pompeo’s aides were upset.

Still, Mr. Pompeo’s willingness to brave the risks in traveling to Kabul and the presidential palace stood in stark contrast to his predecessor, Rex W. Tillerson, the Trump administration’s first secretary of state.

Mr. Tillerson was so concerned about safety that in his visit last year he refused to leave Bagram Air Base, forcing Afghan leaders and his own staff to drive from Kabul to Bagram — a much riskier journey than his own helicopter flight would have been going the other way.