KABUL, Afghanistan — More than 18 years after the United States invaded Afghanistan, President Trump has conditionally approved a peace deal with the Taliban that would withdraw the last American troops from the country, potentially beginning the end of America’s longest war, according to Afghan and American officials.

But the deal will only be signed if the Taliban prove their commitment to a durable reduction of violence over a test period of about seven days later this month. If the Taliban do end hostilities and a deal is signed, the United States would then begin a gradual withdrawal of American troops, and direct negotiations would start between the Taliban and Afghan leaders over the future of their country.

[Update: Taliban ramp up attacks on Afghans after Trump says ‘no violence.’]

Secretary of State Mike Pompeo informed Afghanistan’s top leaders in separate phone calls on Tuesday that Mr. Trump had given tentative approval to this approach, according to a senior Afghan official briefed on one of the calls.

A senior American official aware of the developments also confirmed Mr. Trump had given his preliminary approval for a deal on Monday, dependent on a cessation of violence, the same day he visited Dover Air Force Base to receive the remains of the latest American fatalities in the war, which has killed tens of thousands of Afghans and more than 3,500 American and coalition troops since the United States drove the Taliban from power in 2001.