The sun sets behind the closed Camp X-Ray detention facility, on April 17, 2019, in Guantanamo Bay Naval Base, Cuba.
CNN  — 

The Biden administration repatriated a Guantanamo Bay prisoner to his home country of Afghanistan on Friday after a federal court ruled he was unlawfully detained, an administration official said.

The prisoner, Asadullah Haroon Gul, also known as Haroon Al Afghani, was born in Afghanistan and has been detained in the Guantanamo prison since 2007.

“DOD, supported by other parts of the US government, transferred him out of Guantanamo Bay, facilitating his repatriation to his native country, Afghanistan,” the administration official said. “He flew on a US aircraft to Doha and then we worked with the Taliban and the Qatar government to facilitate his transfer to Kabul.”

Later on Friday the Pentagon confirmed the transfer had taken place.

“The Department of Defense announced today the transfer of Asadullah Haroon al-Afghani also known as ‘Gul’ from the detention facility at Guantanamo Bay to facilitate his repatriation to Afghanistan, his native country,” the Pentagon said in a statement.

“The Department of Defense, in coordination with other USG departments, transferred Mr. Gul in accordance with the U.S. District of Columbia’s order granting his Writ of Habeas Corpus, ruling the United States no longer has a legal basis to justify the continued detention of Mr. Gul,” the statement added.

The transfer also comes as the Taliban leadership in the country has prevented girls above 6th grade from going to school, and as the country faces an economic and food crisis that is expected to kill thousands.

US diplomats who work at the US office for Afghan affairs in Doha engaged with Taliban officials on this topic – which they considered an area of mutual interest – to figure out the logistics of how to make this work, the official explained. There was not any higher level engagement with the Taliban required, the official said.

Late last year, a federal judge ruled that Gul’s detention was unlawful and the Periodic Review Board, which is a panel of officials from different US national security agencies, also cleared him for transfer. Those two decisions triggered the Biden administration to begin working on repatriating Gul.

Gul, an Afghan national who grew up largely in a refugee camp in Shamshato, Pakistan, was accused of being a member of an extremist group called Hezb-e-Islami/Gulbuddin, which was known as HIG at the time. It has since become known as Hezb-e-Islami Afghanistan (HIA). HIA was deemed an “associated force” of al Qaeda by the US government.

Gul conceded that he had been a member of HIG, now known as HIA, at the time, but his defense attorneys argued that the group entered into a peace treaty with the Afghanistan government in 2016.

Gul has been detained at Guantanamo since June 2007.

“A court made the decision that we needed to move this individual somewhere and the most feasible option, the most realistic option is generally going to be repatriation and here seems like it may well prove to be repatriation,” said a source familiar with the matter.

A few factors played into the administration’s efforts to repatriate Gul to Afghanistan, even while the Taliban is currently in control of the country. One of those factors: there are no US service member still in Afghanistan after the US withdrew from the country last fall.

The Taliban also gave assurances to the US government that Gul would not emerge as a threat to the US homeland or to American allies, the US official said.

“We had conversations about how important it is that this individual does not pose threat to the US or to our allies. We received assurances back,” the official said.

The transfer of Gul to Afghanistan comes as tensions between the US and the Taliban remain high over Mark Frerichs, a veteran and contractor who was kidnapped in Kabul in late January 2020, is believed to be held by the Haqqani network, which is a close affiliate of the Taliban.

“We also have to find a way to get Mark home. We are working diligently on that. We hope there is good news in the weeks to come on getting him home at last,” the official explained.

The Periodic Review Board, which first determined that Gul should be cleared to leave, is a government entity created during the Obama administration to determine whether detainees being held at the prison were guilty or not. The Biden administration continues to rely on the board to dictate which prisoners should be sent home.

With Gul’s transfer, 36 detainees remain at the prison, with more than a dozen cleared for transfer.

“They’ll be continued efforts to do what comes after those recommendations, which is approach countries whether their countries of origin or where that’s not feasible or available or advisable other countries and seek to work out repatriation or transfer arrangements that are mutually satisfactory,” the source familiar with the matter explained.

CNN’s Ellie Kaufman contributed to this report.