As part of Bergdahl's release, the United States is turning over five Taliban detainees at the U.S. prison in Guantanamo Bay, Cuba, to the custody of Qatar, the officials said.
Bergdahl's freedom followed a renewed round of indirect U.S.-Taliban talks in recent months, with Qatar acting as intermediary, the officials said.
President Barack Obama announced the release, saying he had called Bergdahl's parents to let them know.
U.S. special operations forces took custody of Bergdahl in a non-violent exchange with Taliban members in eastern Afghanistan, the officials said, adding that he was believed to be in good condition. He was now undergoing a medical examination in Afghanistan.
The exchange took place at about 6 p.m. local time on Saturday, which was at 10:30 a.m. Washington time, a senior official said.
Bergdahl, who is from Idaho, was the only known missing U.S. soldier in the Afghan war that was launched soon after the Sept. 11, 2001 attacks on the United States to dislodge the Taliban from power. He was captured under unknown circumstances in eastern Afghanistan by militants on June 30, 2009, about two months after arriving in the country.
"Today the American people are pleased that we will be able to welcome home Sergeant Bowe Bergdahl, held captive for nearly five years," Obama said in a statement.
"On behalf of the American people, I was honored to call his parents to express our joy that they can expect his safe return, mindful of their courage and sacrifice throughout this ordeal."
The Bergdahl family was in Washington when news of the release broke, a senior U.S. defense official said, without giving details.
Obama announced this week that he would keep 9,800 U.S. troops in Afghanistan, mostly to train Afghan forces, after NATO combat operations cease at the end of 2014. The last soldiers, aside from a small presence at U.S. diplomatic posts, will leave at the end of 2016.
Bergdahl's release could be a national security boost for Obama, whose foreign policy has come under widespread criticism in recent months.
But some members of Congress have in the past criticized the potential release of the five Taliban detainees, particularly Mohammed Fazl, a so-called "high-risk" detainee held at Guantanamo prison since early 2002. Fazl is alleged to be responsible for the killing of thousands of Afghanistan's minority Shiite Muslims between 1998 and 2001.
Reuters first reported the potential swap of Bergdahl for the five Taliban detainees in December 2011.
Bergdahl's release on Saturday was the result of years of and off negotiations that a senior U.S. official, speaking on condition of anonymity, said revived last November when the Taliban signaled it wanted to resume talks on prisoners.
No direct U.S.-Taliban talks were involved, officials said, and messages were past via Qatari officials.
The final stage of negotiations, which took place in the Qatari capital of Doha, began one week ago, the U.S. officials said.
Obama and Qatar's emir spoke on Tuesday and reaffirmed the security conditions under which the Taliban members would be placed while in Qatari custody, they said.
In his statement, Obama thanked Qatar for its role in Bergdahl's release, as well as the Afghan government.
EMOTIONAL RIDE TO FREEDOM
The U.S. defense official said Bergdahl was able to walk and became emotional on his way to freedom.
"Once the was on the helicopter, he wrote on a paper plate, 'SF?'" the official said, referring to the abbreviation for special forces.
"The operators replied loudly, 'Yes, we've been looking for you for a long time.' And at this point, Sergeant Bergdahl broke down."
Bergdahl's release was celebrated back home.
"We were so joyful and relieved when President Obama called us today to give us the news that Bowe is finally coming home!" Bob and Jami Bergdahl said in a statement released through Idaho National Guard. "We cannot wait to wrap our arms around our only son."
It was not yet known when he would be coming back to the United States. But in his hometown, Hailey, Idaho, news of the release prompted celebration.
"Once we heard about it. We were pretty excited," said 17-year-old Real Weatherly, who was making signs Saturday morning and blowing up balloons to hang outside the shop where she works. "We want to let people know he's free. "
Defense Secretary Chuck Hagel, traveling in Asia, said in a statement that Bergdahl would be given "all the support he needs to help him recover from this ordeal, and we are grateful that he will soon be reunited with his family."
Hagel said Qatar would take steps to ensure that U.S. national security would not be endangered by taking in the five Taliban detainees.