DOHA, Qatar — Six days into negotiations that many expect will deliver a preliminary deal to end nearly two decades of United States military presence in Afghanistan, the last stretch is proving to be a difficult balancing act.

Most of the American and Taliban negotiators were stuck in talks late into the night Thursday in the Persian Gulf state of Qatar — but others, including the delegation leaders, were on the road in a region in turmoil, visiting other nations that could have some sway in the outcome.

For both sides, the challenge is to craft a face-saving resolution for all the vested interests that also sets a path for stability in Afghanistan.

At the table in Doha, Qatar’s capital, negotiators were working to address the needs of a Taliban trying to transition to peace and an American administration seeking a withdrawal that could aid a bid for a second term in office.