KABUL, Afghanistan — American and Taliban negotiators are making headway on a deal in which the United States would withdraw troops from Afghanistan in return for a pledge by the Taliban not to allow the country to host terrorist groups like Al Qaeda, senior Taliban officials and Western diplomats said Thursday.

The possibility of an agreement came after a fourth day of face-to-face talks between a delegation led by the American peace envoy, Zalmay Khalilzad, and Taliban officials in Doha, Qatar, where the insurgents have long maintained an office.

But many of the details remained to be ironed out, including how many American troops would be pulled out and over what period of time.

Though Afghan officials did not publicly criticize the emerging outlines of the agreement, they said any end game to the war would have to be finalized in direct negotiations between the government and the Taliban, which the insurgents have so far spurned.