KABUL, Afghanistan — Hajji Ghalib did just what the American military feared he would after his release from the Guantánamo Bay prison camp: He returned to the Afghan battlefield.
But rather than worrying about Mr. Ghalib, the Americans might have considered encouraging him. Lean and weather-beaten, he is now leading the fight against the Taliban and the Islamic State across a stretch of eastern Afghanistan.
His effectiveness has led to appointments as the Afghan government’s senior representative in some of the country’s most war-ravaged districts. Afghan and American officials alike describe him as a fiercely effective fighter against the insurgency, and the American military sometimes supports his men with airstrikes — although Mr. Ghalib complains that there are too few bombers and drones for his taste.
Accounts of former Guantánamo detainees who went on to fight alongside the Taliban or Islamic State have become familiar. So are those of innocents swept up in the American dragnet and dumped in the prison camp without recourse or appeal. But this is a new one: the story of a man wrongly branded an enemy combatant and imprisoned in Guantánamo for four years, only to emerge as a steadfast American ally on the battlefield.
At 54, Mr. Ghalib’s face is creased, and his eyes are both exhausted and watchful, as though all they really expect to see is the next bad turn that will befall his life. There have been many, including the death of both wives, his daughters, a sister and a grandchild at the hands of the Taliban.
“I don’t have good memories of life, to be honest,” Mr. Ghalib said.
In a recent interview in Kabul, he cataloged the enemies he has fought during a life of struggle — first the Soviets, during the jihad of the 1980s; then the Taliban over the next three decades; and now the Islamic State.
More slowly, he recounted the long list of relatives he lost over these decades of calamity, from a brother who died in the war against the Soviets in the 1980s to his 70-year-old brother-in-law, who was beheaded this month. The Taliban killed more than 19 relatives in all.
“Everything has been fighting and killing,” he lamented.
Now, his latest fight has even pitted him against a man he once considered a close friend: a poet named Abdul Rahim Muslim Dost, whom he lived alongside in Guantánamo.
While Mr. Ghalib chose to reject bitterness and fight on behalf of the American-backed government, his former friend Mr. Dost now leads the Islamic State fighters whom Mr. Ghalib’s forces are trying to drive out of eastern Afghanistan.
But years ago, stuck in the same camp at Guantánamo, they would spend their days debating politics and religion.
Mr. Dost, a dour but quick-witted man who was known for the poetry he etched into the side of coffee cups for lack of better writing materials, was adamant that there was only one course of action after their release: Go to Pakistan and start waging jihad. He spoke of uniting the whole Muslim world.
Mr. Ghalib had other plans. “I used to argue with them that we are Afghans and we must support Afghanistan,” he said, meaning the current, American-backed government that replaced the Taliban. It was the minority view, but he did not worry about sharing it with Mr. Dost or any of his jailed countrymen. “We were friends with each other despite our views,” he said.
How Mr. Ghalib ended up in American captivity is its own bewildering story. After building a reputation as an effective commander against the Soviets and the Taliban, he became a police chief for the new Afghan government after the Taliban’s ouster in 2001. But in 2003, he was arrested after United States soldiers found explosive devices adjacent to the government compound where he worked. That was apparently close enough. There were also several letters that linked him to Taliban figures, although American officials conceded the letters might have been forged.
One of the military officers weighing the evidence against him explained that he did not “put much credibility to any of these letters,” according to a transcript of the tribunal.
That left Mr. Ghalib flummoxed. “So why are you detaining me?”
At Guantánamo, Mr. Ghalib often explained to his captors that he had been fighting the Taliban for years and had even aided American forces at Tora Bora against Al Qaeda. He recited the names of major anti-Taliban commanders who would vouch for him.
American investigators eventually concluded that the “detainee is not assessed as being a member of Al Qaeda or the Taliban,” according to a military document outlining the evidence. Yet the military nonetheless described Mr. Ghalib as “a medium risk,” noting that he could possibly become a formidable enemy given his years of experience as a combat commander — albeit on the government’s side before his detainment.
Finally, in 2007, Mr. Ghalib was released.
He left Guantánamo angry not only over the “psychological torture” the American military put him through, but also at the Afghan government for never pushing for his release, he recalled. Yet he was determined not to let the hardship of the past four years alter the course of his life.
Mr. Ghalib decided that he would be guided by “the overall pain that my people and my country are going through — that is the most important thing.”
But his own sorrows would only grow in the coming years.
“My dream was to go back and live peacefully at home,” Mr. Ghalib said. “But nobody let me do that.”
It began with a road, or at least the idea of a road, that his tribe, the Shinwari, wanted built in Mr. Ghalib’s home district in Nangarhar Province. As a tribal elder, Mr. Ghalib took a leading role in the internationally financed project.
Almost immediately, the Taliban began to threaten him for working with the foreigners, and soon the insurgents began assassinating his relatives.
Among the first to die was Mr. Ghalib’s brother, caught on his way home from a mosque. After the Ramadan holiday in 2013, the extended family gathered at the gravesite to mourn. But the Taliban had dug up the gravesite and buried a bomb there to punish the family further.
“Eighteen members of my family were killed in that attack,” Mr. Ghalib recounted — almost all women and children.
“My family is finished,” Mr. Ghalib told The Associated Press that afternoon, calling the Taliban “inhuman.”
Back then, Mr. Ghalib had been on a local peace commission, one of many tribal elders seeking to encourage reconciliation with the insurgents. But President Hamid Karzai offered him a chance for revenge. He had little family to look after, and the Taliban would keep coming after him, Mr. Ghalib recalled the president telling him. The president got him a job as governor of Bati Kot, a Taliban-infested district straddling a highway to Pakistan. He quickly organized a local police force and began going after the Taliban.
“When I got into the government, I started to destroy them,” Mr. Ghalib recalled. The Taliban tried to placate him, he said, recalling an unusual phone call he received: The insurgent commander on the line offered to find whoever had planted the bomb at his brother’s grave and hang him.
Mr. Ghalib rejected the terms. “I told them that our enmity has just started.”
This summer, his Shinwari tribesman requested that he be transferred two districts south, to rescue a benighted region called Achin, where a belt of villages had fallen to a new threat: Islamic State fighters under the command of Mr. Dost, his old friend from Guantánamo. The militants had pushed 10 tribal elders into an explosives-lined trench and videotaped the blast that killed them.
When Mr. Ghalib arrived as the new district governor, he placed on his desk a photograph of his 2-year old grandson, killed in the cemetery bombing. “Each time I look at it, it makes my heart burst and that motivates me,” he said. “That’s why I carry on all the operations myself.”
In one battle this summer, Mr. Ghalib described how he and his son led a force of police officers and soldiers against Islamic State fighters who were threatening to overrun Achin’s small district center. After being hit by multiple roadside bomb explosions, most of the forces fell back, leaving Mr. Ghalib and his son alone to face some 15 Islamic State fighters.
“We were able to shoot many,” he said.
At such times, Mr. Ghalib said, he would not be surprised to find Mr. Dost among the jihadists shooting back at him — the rumor is that Mr. Dost is usually on the front lines.
But Mr. Ghalib said that he would have little to say to Mr. Dost at this point: “He slaughters civilians, innocent people and children.”
“We will not spare him if I face him on the battlefield,” Mr. Ghalib said matter-of-factly. And given the chance, he said, “he will also not leave me alive.”
The two last saw each other a decade ago, in 2005, in Guantánamo. The Americans had concluded that Mr. Dost was no longer a threat and sent him home.
“It is very ironic that Muslim Dost got released before me,” Mr. Ghalib said. He himself had two more years to go before the Americans finally released him, too.