KABUL — U.S. and Taliban officials have moved closer to an agreement that could meet a Taliban demand for withdrawing U.S. troops from Afghanistan, officials here indicated Monday, a potential step toward ending more than 17 years of American involvement in the country’s long conflict.

Afghan President Ashraf Ghani, speaking from his palace in Kabul, addressed what appeared to be a significant breakthrough in talks between American officials and Taliban representatives in Doha, Qatar, calling on insurgents to begin “serious talks” with his government and embrace a “speedy peace.”

The tentative agreement for a framework to pull out U.S. troops, in exchange for Taliban promises to deny al-Qaeda and the Islamic State a foothold on Afghan soil, comes as Washington races to clinch a deal just weeks after President Trump ordered the withdrawal of up to half of the 14,000 American troops in the country but stopped short of announcing the plan.

But both U.S. and Afghan officials said several major issues remain to be resolved before a peace agreement can be reached, including U.S. demands for an extended cease-fire and the Afghan government’s insistence on being included in talks about the Taliban’s future role in government and society.

Strong support across the U.S. government for a political solution reflects a recognition of the elusiveness of a military victory against a militant group that has defied almost two decades of warfare with U.S. and NATO forces.

It also reflects the toll that a war that began in the wake of the Sept. 11, 2001, attacks has taken on Afghanistan’s people, government and economy.

During six days of talks in Qatar last week, Taliban and U.S. representatives outlined but did not formally agree on a broad plan in which U.S. troops would leave the country in exchange for the insurgents pledging to ensure that Afghan territory would not be used by them or other Islamist militant groups to harm American interests.

Significant obstacles remain to reaching a peace deal, though — or even beginning substantive talks.

“This is a major breakthrough. It’s the closest we’ve ever been to ending this 18-year war. But a framework shouldn’t be mistaken for a deal. There is still a lot to flesh out,” said Michael Kugelman, deputy director of the Asia program at the Wilson Center. “Above all, the Afghan government needs to be brought into these discussions. And even with all this momentum, a fundamental challenge will remain in place: how to ensure that the Taliban holds up its end of the bargain and doesn’t take up arms again, in the event of a deal.”

Though U.S. officials expressed cautious optimism Monday, the Pentagon hasn’t adjusted its plans to continue aiding Afghan national forces fighting the Taliban.

In Washington, acting defense secretary Patrick Shanahan called the developments “encouraging” but said he had not been asked to prepare for a full troop withdrawal.

News of a potential breakthrough generated anxiety within the Afghan government, which has been excluded from the talks because the insurgents view it as an American puppet. Speaking in a televised address, Ghani warned that a deal without Afghan government involvement could lead to the kind of “catastrophic” civil strife that followed the Soviet troop withdrawal from Afghanistan in 1989.

U.S.-Taliban talks appear closer to pact after marathon negotiations in Qatar

Speaking after being briefed by Zalmay Khalilzad, the Trump administration’s special envoy for Afghan peace, Ghani assured Afghans that he would not accept a deal that undermines their rights and the nation’s unity.

Khalilzad told the New York Times on Monday that U.S. and Taliban officials had agreed in principle on the two key elements of an eventual deal. But he said a U.S. troop pullout still hinges on the Taliban’s acceptance of a cease-fire and direct talks with the Afghan government on domestic issues as part of a full-fledged peace accord.

“Nothing is agreed until everything is agreed, and ‘everything’ must include an intra-Afghan dialogue and comprehensive ceasefire,” he said Saturday on Twitter after leaving Doha. Talks between the two sides are expected to resume next month.

Ghani, who met with Khalilzad late Sunday in Kabul, said in his speech that no agreements would be concluded without the government’s full participation.

Taliban officials, for their part, issued a statement late Saturday saying that progress had been made but that further talks were needed to deal with “unsolved matters.” The statement added pointedly that Taliban policy was made “very clear” during the talks: “Until the issue of withdrawal of foreign forces from Afghanistan is agreed upon, progress in other issues is impossible.”

Among crucial issues to be addressed in future talks are the Taliban’s role in a post-peace governing system and the extent to which its strict Islamic codes could be reimposed on a society that has known democratic freedoms for the past 17 years. A statement from Ghani’s office on Monday said Khalilzad told him the Doha talks did not include such issues.

The issue of Afghan inclusion in the peace process is especially sensitive for Ghani, who is seeking reelection in a vote slated for July. He has opposed suggestions that an interim government be formed to implement a peace plan, and he has expressed concern that a hasty U.S.-Taliban deal could come at the expense of Afghan democracy and freedoms.

Trump wanted a big Afghanistan troop cut. New U.S. military plans fall short.

Several Afghan critics derided Ghani’s assertion that his government would be consulted on U.S. troop pullout plans. They noted that Trump has already said he wants to withdraw thousands of troops and that Khalilzad has been under White House pressure to arrange a deal with the Taliban as fast as possible.

“America does not need our advice or consultation for leaving. It came here for its own interests, and it will leave for its own interests,” said Hafiz Mansour, an opposition legislator. “Trump can decide to pull out troops at any moment, and the U.S. is looking for a face-saving approach to do it. But our troops do not have the capacity to defend the country. We will need foreign help for years to come.”

Trump’s troop reduction plans have dismayed military officials who have said Afghan forces require ongoing help to execute offensives and defend urban centers.

Ghani has worked closely with U.S. military officials since taking office, strongly endorsing a buildup in U.S. training and advising of Afghan forces over the past two years. At an international economic conference last week in Davos, Switzerland, Ghani said that 45,000 members of the Afghan security forces had died since he took office in 2014, a much higher toll than previously reported.

Washington’s push for a deal comes 18 months after the president — initially setting aside his impulse to order an immediate withdrawal — approved a strategy for Afghanistan that included thousands more U.S. troops and more-aggressive rules of engagement.

Since then, the president has grown impatient with the lack of progress, as a stalemate between U.S.-backed Afghan forces and the Taliban persisted and violence continued to spike.

Against that backdrop, according to Barnett Rubin, a former State Department official and Afghanistan expert at New York University, U.S. negotiators have been authorized for the first time to put the withdrawal of American troops on the table in their talks with militant representatives.

“Our national security strategy has now changed so that fighting terrorism is no longer our top priority,” Rubin said, referring to the Pentagon’s new focus on competing with China and Russia. “So we don’t want to have so much of our resources tied up in Afghanistan.”

Even if a peace deal emerges with the Taliban, both Washington and Kabul still have to contend with a common enemy in the Islamic State, an offshoot of which has been carrying out attacks in Afghanistan.

The Pentagon might theoretically seek to withdraw the bulk of troops under a peace deal but leave a counterterrorism mission in the country to combat the Islamic State and al-Qaeda — or conduct periodic strikes from outside Afghanistan.

Hanging over the flurry of diplomatic efforts are questions about how much time Trump will allow to attempt a negotiated solution.

“The American departure could be 280 characters away,” said Christopher Kolenda, a retired Army colonel who commanded troops in Afghanistan and took part in talks with the Taliban during the Obama administration. “The question is: Does the United States depart as part of a durable peace agreement that supports our interests, or does it depart in a way that allows Afghanistan to descend to a new level of civil war?”

Sonne and Ryan reported from Washington.

Pelosi abandons Afghanistan trip, accuses Trump of imperiling lawmakers with disclosure

U.S. troop drawdown in Afghanistan raises big questions

Afghan forces use artillery to repel multiple Taliban assaults that kill at least 21

Today’s coverage from Post correspondents around the world

Like Washington Post World on Facebook and stay updated on foreign news