SHEBERGHAN, Afghanistan — The top commander of the Islamic State in northern Afghanistan stood behind a lectern decorated with the shield of the Afghan government’s powerful intelligence agency.

On his left was the police general in charge of the province. Arrayed behind him was an assortment of other dignitaries: police, army, political figures. An attendant put a bottle of mineral water nearby, in case the intense heat made the commander thirsty.

This is how the Islamic State commander, Maulavi Habib ul-Rahman, began his “imprisonment” on Thursday. Along with 250 of his fighters, Mr. Rahman had surrendered the day before to the Afghan government in the northern province of Jowzjan, to avoid being captured by the Taliban.

He thanked his hosts and, in a scolding tone, warned them to stick to the deal they had just made. “Provide us with personal security as well as stay loyal to the commitments made between us so it prepares the ground for others who fight against the government to join the peace process,” Mr. Rahman demanded from the dais.