U.S. and Taliban representatives say six days of talks have produced progress toward a potential agreement that would see Washington withdraw American troops within 18 months and the insurgents commit to preventing al Qaeda or other extremists to use the country as a base for terrorism.

The duration and scope of the talks in Doha between U.S. special envoy Zalmay Khalilzad and senior Taliban figures was unprecedented, former diplomats and experts said, and positive public statements by both sides raised the tantalizing prospect of a negotiated end to the 17-year-old war.

“I’m more optimistic than ever before. I think we’re much closer to a possible settlement than we have been in the past — at least 17 years and particularly in the last few years,” said Hekmat Karzai, director of the Centre for Conflict and Peace Studies in Kabul.

Taliban walk as they celebrate ceasefire in Ghanikhel district of Nangarhar province, Afghanistan on June 16, 2018. Parwiz / Reuters file

But while both Khalilzad and the Taliban struck a positive tone afterward, it was also clear that crucial issues that have long proved to be stumbling blocks remained unresolved.

"Reports by some media outlets about agreement on a ceasefire and talks with the Kabul administration are not true," Taliban spokesman Zabihullah Mujahid said in a statement Saturday.

The U.S. envoy said the agreement would need to include a ceasefire and a pledge from the Taliban to enter into negotiations with the Afghan government. But the Taliban has so far rejected a ceasefire and refused to recognize the Western-backed government in Kabul, referring to Afghan President Ashraf Ghani as an American puppet.

The U.S. envoy departed Doha Saturday night and was flying to Kabul for consultations with an Afghan government that fears Washington is overly eager to strike a deal with their adversaries.

In a series of tweets, Khalilzad said discussions were “more productive than they have been in the past. We made significant progress on vital issues.”

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

1/3 After six days in Doha, I'm headed to #Afghanistan for consultations. Meetings here were more productive than they have been in the past. We made significant progress on vital issues. — U.S. Special Representative Zalmay Khalilzad (@US4AfghanPeace) January 26, 2019

But he said that there were “a number of issues left to work out” and that there could be no deal without a cease-fire and a dialogue among Afghans. “Nothing is agreed until everything is agreed.”

Foreign diplomats, former U.S. diplomats and experts said the talks showed promise, but that it was unclear if the United States could persuade the Taliban to make concessions it has long resisted.

Karzai, the former deputy foreign minister, said he was “quite encouraged” by the talks but added: “I think the Taliban and the U.S. government have come to an agreement on certain issues but they still are far away from agreement on a few other issues.”

Experts and former diplomats say the Taliban have the upper hand in the negotiations as they have gained ground on the battlefield and are keenly aware of President Donald Trump’s desire to pull U.S. troops out of Afghanistan before his term ends in two years.

Laurel Miller, a former senior State Department diplomat who oversaw Afghanistan and Pakistan policy, said the public comments by both sides amounted to “dueling statements on some pretty fundamental questions.”

Afghanistan's President Ashraf Ghani announced recently that he would seek a second term after forging an alliance with a staunch critic to challenge his former governing partners. Laurent Gillieron / EPA

In the past, the U.S. was reluctant to enter into talks with the Taliban without the participation and approval of the Afghan government. But the United States is hoping that an initial agreement between the United States and the Taliban — setting out a ceasefire and a timeline for a U.S. troop withdrawal — could open the door to peace negotiations between the insurgents and the U.S.-backed Afghan government.

The question is whether the U.S.-Taliban dialogue creates momentum for a broader peace deal, or merely confirms an American exit with few protections for the Afghan government.

“There’s also the possibility, that a deal — that’s really just a deal between the U.S. and the Taliban — emerges in a way that provides a cover for an exit but not much more,” said Miller, now director of the Asia program at the International Crisis Group.

“What we’ve seen so far doesn’t give us clarity as to which direction this is going to go,” she said.

Foreign diplomats familiar with the talks told NBC News that Afghan government officials are extremely anxious about the U.S. discussions with the Taliban, and Khalilzad’s meeting with Ghani was expected to be difficult. At the World Economic Forum in Davos, Ghani said his government needed to be consulted about the diplomacy with the Taliban.

One Western official said the “wishes of the Afghan government and people rate pretty low” in Washington’s calculations.

“The fear of being sold out is palpable among Afghans. But Ambassador Khalilzad is enormously talented and well aware of his place in history. He will not go down in history as having sold out Afghanistan,” said David Sedney, a former senior U.S. defense official and now senior associate at the Center for Strategic and International Studies.

Even as talks have progressed over the past few months, the Taliban have kept up attacks on the Afghan government, including a devastating assault targeting an intelligence office on Monday.

Khalilzad will have to sell a possible deal to Trump, as well as intelligence and military leaders. Although Trump is keen to see a U.S. exit, the Pentagon and the intelligence community will want to see firm and specific guarantees that the Taliban pledges publicly to sever all support or ties to al Qaeda, former officials said.

The Taliban previously have stopped short of such a promise.

Academics and former officials have said Pakistan, the patrons of the Taliban, was playing a significant role in the talks, unlike in some discussions when it was accused of undermining diplomacy. This time, Islamabad believes Washington is serious and that the dialogue represents an opportunity to maintain its influence in Afghanistan, where it fears its archfoe India could assert itself, experts said.

The Pakistanis released a key Taliban figure, Mullah Abdul Ghani Baradar last year, allowing him to take part in talks with the Americans. His appointment recently as chief Taliban negotiator and new deputy head of the Taliban signals the insurgency is ready to forge an agreement with the United States, experts said.