FAIZABAD, Afghanistan — They paced aimlessly inside a guarded compound, stepping over their beard and hair clippings on the ground. Ninety-eight Taliban in all — fighters as young as 16 and as old as one white-bearded veteran of 65.
They had all laid down their weapons and pledged loyalty to the Afghan government. But the reasons for that depended on who was telling the tale — and illuminated some of the complexity of a war in which side-switching is common.
The Afghan military says these Taliban fighters quit to try to save their lives after Afghan forces retook three districts from the Taliban during desperate, pitched battles in the northeastern province of Badakhshan in September.
The fighters had been told by the head of the national intelligence agency in the province that they were free to return to civilian life if they renounced the Taliban.
Others said they had been given no choice but to surrender at gunpoint, then submitted to having their typical Taliban style — long hair and beards — trimmed back by a barber.
But they were not speaking freely. They related their stories to visiting New York Times journalists in the presence of a glowering officer from the National Directorate of Security, who often interrupted to correct or admonish them for speaking too frankly.
The courtyard spectacle had all the trappings of a practiced performance, with the fighters politely agreeing with the intelligence officer. But whenever he stepped away, they offered more candid assessments.
Several of the men spoke of reluctantly joining the Taliban only after their districts were seized by the militants up to four years ago. They shared a common resentment: the foreign jihadists — from Pakistan, China, Tajikistan and Turkmenistan — who commandeered their homes and demanded food.
Brig. Gen. Mohammad Hanif Nuristani, the government intelligence commander in Badakhshan, said there were at least 400 foreign fighters in the province who had joined the Taliban, Al Qaeda or the Islamic State.
“They didn’t speak our language, but we shared our food,” said Sultan Mohammad, 46, who said he commanded 15 Taliban fighters. “We had no choice, and to protect our families, we supported them.”
Mr. Mohammad, who said he was a teacher who supported the government before the Taliban takeover, said he had been in touch by telephone with local government leaders before and during the battles in September.
Asked whether he and his men had surrendered or had been captured, Mr. Mohammed replied, “We weren’t captured. We support the government, inshallah.”
Nizamuddin, 19, who goes by one name, said he had eagerly joined the Taliban this year because he was intrigued by what he called “their ideology.” But when the Afghan military attacked, he said, his older brother — a government intelligence officer — telephoned and persuaded him to defect.
He said he switched sides because of the foreign jihadists, whose presence he said drew American airstrikes. “We didn’t want them in our homeland but we had no choice,” he said.
The intelligence officer, a stocky man in a shiny blue suit who declined to give his name, said the government had provided food, showers and living space for the fighters. At their request, he provided a barber to trim their long hair and wild beards, he said.
“We want to look like the government people,” one fighter announced, and his companions laughed uproariously.
The intelligence officer said the fighters, who were allowed to keep their cellphones to reach family members, would be permitted to return home soon. He said they were free to leave the compound, but it was surrounded by armed intelligence agency soldiers who blocked the front entrance.
The fighters had been taken recently to attend a ceremony in Faizabad, the provincial capital, with the government’s national security adviser, Hamdullah Mohib. In a Twitter post, Mr. Mohib said the men had renounced violence. He praised them for “choosing the right way” and “endorsing” the government’s legitimacy.
Abdullah Naji Nazari, a member of the provincial council, said the fighters “didn’t like the Taliban anymore” and now trusted government forces to help them secure their villages.
General Nuristani said the fighters had provided valuable intelligence. “Perhaps we’ll send them back as spies for us,” he said.
In the courtyard, Mohammad Hassan, a wiry little man who thought he was about 65 years old, said he had fired rocket-propelled grenades at Soviet soldiers in the 1980s and at government troops this year while fighting for the Taliban.
Now, he said, he was perfectly willing to fire the same weapon at his former Taliban comrades, if only the government would arm him. He had been a farmer before joining the Taliban, he said, but now he wanted nothing more than to fight.
“Some people like gardening or parrots,” he said, grinning. “I like to fight.”
His comrades doubled over in laughter. One of them slapped the old man on the back.
“I’m addicted to war,” Mr. Hassan continued. “My nickname is Hassan Rocket!”
There was more laughter, even from the weapons-toting intelligence agency guards.
The spectacle inside the courtyard soon drew to a close, with the intelligence officer signaling that it was time to wrap up. The visitors withdrew. The fighters, some who seemed to have surrendered and some who perhaps had defected, resumed pacing the compound.
One of the guards watched them warily.
“Every one of them is dangerous,” he said. “We don’t trust a single one.”
Najim Rahim contributed reporting.