The prisoner swap came after secret talks between the US government and the Taliban, brokered by Qatar.
Bergdahl was serving with an Alaska-based infantry regiment in Paktika province near the Pakistani border and went missing on 30 June 2009, five months after being deployed to Afghanistan.
The circumstances of his capture remain murky, with speculation he may have walked away from his base out of disillusionment with the US campaign.  In March 2015, he was charged with desertion and misbehaviour before the enemy.
The US believes he was across the frontier in Pakistan for most of his captivity, reportedly held by the Haqqani network, which operates in the Afghanistan-Pakistan border region and is allied to the Afghan Taliban.
Profile: Sgt Bowe Bergdahl
The circumstances of Sgt Bergdahl's capture in 2009 remain unclear, although a Pentagon investigation a year later concluded he left his post in Paktika Province without authorisation, according to a Pentagon official speaking to Associated Press news agency.
Several commentators and soldiers have branded him a deserter and called for him to be punished.
The New York Times said on his disappearance in 2009 had noted he had left military areas before, during a training programme in California and an Afghan outpost, but returned each time.
US officials told the newspaper the report did not conclude whether Sgt Bergdahl had intended to permanently desert the military.
The US military's top-ranking officer, Gen Martin Dempsey, has that the Army would not ignore misconduct but that the 28-year-old was innocent until proven guilty. "When he is able to provide the facts, we'll learn what happened."
The defence department opened up an investigation into his disappearance and capture, appointing a two-star general with combat experience in Afghanistan to lead the inquiry.
Taliban officials say the 28-year-old was handed over near Khost, close to the the Afghan-Pakistan border, on the evening of 31 May. A several-dozen strong US special forces team flew in by helicopter and briefly met some 18 Taliban on the ground.
The exchange, captured on video, shows Sgt Bergdahl sitting in a pick-up truck before being walked to the helicopter.
Once the helicopter was in the air, Bergdahl wrote the letters "SF?" on a paper plate - an abbreviation for special forces - and reportedly broke down when the men responded: "Yes, we've been looking for you for a long time."
Taliban release video of handover
Sgt Bergdahl was the only US soldier being held by the enemy in the Afghan conflict, and Washington had long been seeking his release, spurred on by the "Standing with Bowe" campaign led by his parents in Hailey, Idaho.
Negotiations for the US-Taliban prisoner swap began three years ago with US and Taliban officials meeting face-to-face in Qatar.
But the talks did not move forward because the US were pushing for a wider peace process, while the Taliban wanted to limit the talks to a prisoner swap, Taliban sources told the BBC's David Loyn in Kabul.
Direct negotiations broke down a year ago when the Afghan government opposed the opening of a Taliban office in Qatar, although secret talks continued, mediated by Qatar.
The issue was given more impetus as plans solidified to pull nearly all American forces out of Afghanistan by the end of 2016. US sources say the breakthrough came when hardline Taliban leaders dropped their opposition to a swap.
On Thursday, Mr Obama said Sgt Bergdahl's health was deteriorating and officials were "deeply concerned about it".
But the prisoner swap was apparently sped up after US officials determined the Taliban would likely kill Sgt Bergdahl if any word of the deal was leaked, according to congressional and White House sources who spoke to the Associated Press.
Defence Secretary Chuck Hagel told the BBC's Katty Kay he and other military chiefs based their decision "on the information that we had, that his life, his health, were in peril".
His father Robert Bergdahl said Bowe was struggling to speak English after his long captivity. In an emotional White House lawn press conference with Barack Obama shortly after the release, Robert Bergdahl delivered his son a message in Pashto, the language of his captors.
After immediate medical attention at a military hospital in Germany,  Sgt Bergdahl was flown to San Antonio, Texas, to continue treatment.
On Friday, Army officials said he was in a "stable condition".
He "looked good", was in uniform, and saluted, Maj Gen Joseph DiSalvo said.
"He appeared just like any sergeant would when they see a two-star general - a little bit nervous," Gen DiSalvo said. "But he looked good, saluted, and had good deportment."
Can you lose your language?
The exchanged prisoners are Mohammad Fazl, Khirullah Khairkhwa, Abdul Haq Wasiq, Mullah Norullah Noori and Mohammad Nabi Omari.
They are thought to be the most senior Afghans still held at Guantanamo, having been captured during America's military campaign in 2001.
Fazl served as the Taliban's deputy defence minister and is accused of possible war crimes, including the murder of thousands of Shia Muslims.
Khairkhwa served as interior minister and governor of Herat, Afghanistan's third largest city. He is alleged to have had direct links to Osama bin Laden.
US President Barack Obama says Qatar has given assurances "that it will put in place measures to protect our national security".
Under the deal, the five freed Taliban detainees will be banned from leaving Qatar for at least a year, meaning they cannot return to Afghanistan until after a majority of US forces have left.
The Associated Press' Kathy Gannon, who was shot in Afghanistan while covering the recent elections, says the five men are important but not likely to change the balance of the war - and having been away from Afghanistan for more than a decade, they would not find Taliban foot soldiers very loyal.
Some argue there is US precedent for this type of transfer, with Ronald Reagan's administration in 1985-86 reportedly winning the freedom of US hostages in Beirut in exchange for arms destined for Iran.
But Mike Rogers, the Republican chairman of the House of Representatives Intelligence Committee, called it a fundamental shift in policy that would act as an incentive for further abductions of US personnel.
Some US lawmakers have complained the swap breaches a law that Congress should be given 30 days' notification before Guantanamo Bay detainees are released. The White House says it took the chance to free Sgt Bergdahl in "unique and exigent circumstances".
Democratic Senator Dianne Feinstein, normally a White House ally, was enraged that the president had not notified her or the intelligence committee she leads, of the pending swap, although a White House official did call her on Monday to apologise for the delay.
The US has a long-standing policy not to negotiate with those it deems terrorists and the prisoner swap has drawn criticism - especially from conservatives.
Republican Senator John McCain told the BBC the swaps "threatened" US security, as the detainees released were too dangerous to be walking free, and would put other US military lives at risk. Other lawmakers have called for a inquiry into the administration and military's decision making process.
But Mr Obama is publically unapologetic for the swap.
"We saw an opportunity and we seized it," he said, adding "as commander-in-chief I am responsible for those kids".
No Obama apology for Bergdahl deal
Correspondents say it is unclear what impact the release will have on a wider peace process.
The Afghan High Peace Council want talks with the Taliban to happen inside Afghanistan, and does not want to involve the Americans.
Bowe Bergdahl returned to the US on 13 June 2014, arriving at a medical centre in Texas where he finished the last phase of his reintegration process.
In his hometown of Hailey, Idaho, a rally scheduled months ahead was quickly turned into a homecoming event that was cancelled.
City officials cited safety concerns, because of a large increase in the number of expected attendees, and local officials have received messages blasting the town for honouring Sgt Bergdahl's return.
Sgt Bergdahl returned to active duty in July, working at a desk job at Joint Base San Antonio-Fort Sam Houston.
In March 2015, he was charged with desertion with intent to shirk important or hazardous duty and misbehaviour before the enemy by endangering the safety of a command unit or place.
A preliminary hearing will be heard in front of a judge at Fort Sam Houston. A date has not been set for that hearing.
He faces up to five years in prison on the desertion charge and life in prison on the misbehaviour charge.
How to 'reintegrate' a returning POW
US Sgt Bowe Bergdahl has been released five years after being captured by Afghan Taliban, in a controversial exchange for five Taliban officials being held at Guantanamo Bay.