The resumption of any peace negotiations would be further complicated by the Afghan presidential elections in September that were mired by violence, low turnout and an unclear victor. Initial results, which were expected on Saturday, have been delayed at least a week.

With Washington’s strategy unclear, the United States-led mission in Afghanistan has continued its campaign to target and kill the Taliban at levels not seen since the height of the war.

But the increase in operations has not been without a cost. More than 1,000 civilians were killed in the past four months, the United Nations said. On Friday, a suicide bomber killed more than 70 people at a mosque in Nangarhar Province.

Mr. Esper, a futurist who is trying to focus the Pentagon on confronting China and Russia, is instead now dealing with the hasty retreat of American forces from northern Syria and a new deployment of 2,000 troops to Saudi Arabia in an effort to curb what the White House sees as a growing threat from Iran. Some of the troops may withdraw to Iraq, Jordan, Europe or the United States, officials said at the time.

Mr. Trump’s order for the troop withdrawal from northern Syria opened the door for a Turkish incursion into the region and deadly clashes with Kurdish fighters, until Vice President Mike Pence brokered a cease-fire last week.

In a post on Twitter on Sunday that misstated Mr. Esper’s surname, Mr. Trump wrote:

“Mark Esperanto, Secretary of Defense, ‘The cease-fire is holding up very nicely. There are some minor skirmishes that have ended quickly. New areas being resettled with the Kurds.’ USA soldiers are not in combat or cease-fire zones. We have secured the Oil. Bringing soldiers home!” He later corrected the spelling of Esper.

For Ms. Pelosi, it was her first trip to Afghanistan since her term as speaker began in January. She had planned to visit American troops in the country in January, days after taking the speaker’s gavel, but the trip came as she was sparring with the White House over how to end a partial government shutdown.