The only American known to be held by the Taliban in Afghanistan has been freed, U.S. officials announced Saturday.

Sgt. Bowe Bergdahl, who was captured by insurgents nearly five years ago, is in the custody of U.S. special operations forces in Afghanistan. He is believed to be in good condition and is being examined by doctors, Reuters reports.

Bergdahl was reportedly released in exchange for five Taliban detainees held in the detention facility at Guantanamo Bay in Cuba. The prisoners were released into the custody of the government of Qatar.

In a statement, Secretary of Defense Chuck Hagel said the U.S. had coordinated “closely” with Qatar to ensure the detainee transfer would not compromise national security.

“I appreciate the efforts of the Emir of Qatar to put these measures in place, and I want to thank him for his instrumental role in facilitating the return of Sgt. Bergdahl,” Hagel said.

Bergdahl was the only known soldier missing in the Afghan war. He was captured on June 30, 2009, under unclear circumstances in eastern Afghanistan.

In recent months, the captors behind Bergdahl’s detention had signaled a willingness to release him, but were waiting to make a deal with American officials.

President Barack Obama released a statement in which he called Bergdahl’s recovery, “a reminder of America’s unwavering commitment to leave no man or woman in uniform behind on the battlefield.”

“And as we find relief in Bowe’s recovery, our thoughts and prayers are with those other Americans whose release we continue to pursue,” he said.