Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

FORT BRAGG, N.C. — In an unexpected move, Army Sgt. Bowe Bergdahl took the stand in his sentencing hearing Monday, breaking down several times and apologizing to those who were wounded while searching for him after he abandoned his post in Afghanistan.

"I was trying to do something good and it turned bad," Bergdahl said, reading from a statement at the beginning of his testimony. "My words alone can't relieve the pain. ... I think about what I did every day for the last eight years."

Aside from when Bergdahl pleaded guilty to desertion and misbehavior before the enemy, it was the first time the courtroom had heard from him. His appearance came as a surprise to courthouse reporters, who were told another witness would be testifying Monday afternoon.

Bergdahl abandoned his post in Afghanistan on June 30, 2009 — a move he called a "terrible mistake" on Monday — and then was captured by the Taliban. On the stand, he detailed several unsuccessful escape attempts. Each time he tried to break away, he said, his captors secured him more tightly, using bigger chains, and beat him.

As his years in captivity dragged on, it became more and more difficult to stand up, Bergdahl told the court. He recalled painful bed sores and said his captors burned the bottoms of his feet. He described having uncontrollable diarrhea, and open sores on his ankles and his head where a blindfold rubbed against his skin.

His captors only took him to the bathroom once or twice a day, Bergdahl said. He was held in various locations, including a bed he was chained to, a mat or a blanket on the ground, and mud or cement compounds. His captors showed him videos of executions and pointed AK-47s at his head, Bergdahl said.

He started crying multiple times, at one point shaking his head, too overcome with emotion to answer a question about from the defense about what else his captors did to him.

At one point in the first year, Bergdahl escaped for eight days, he said. Once he got out, he fell down a cliff into a river bed and sustained injuries that still bother him to this day, he said. When his captors found him, he was taken to a new location and placed in a 6-foot-wide cage that had been built for him, he added.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Bergdahl's testimony came on a busy day in court, which began with the military judge who will be deciding his sentencing denying a motion by defense attorneys to dismiss the case based on comments made by President Donald Trump.

The court also heard heart-wrenching testimony from the wife of a soldier seriously injured in the search for Bergdahl.

"He’s lost me as a wife, essentially, because instead of being his wife, I’m his caregiver," said Shannon Allen, whose husband, Master Sgt. Mark Allen, was shot in the head. "I mean, we can’t hold hands anymore, unless I pry open his hand and place mine in it."

A contrite Bergdahl addressed those who were injured looking for him, ended his opening statement with: "Thank you for your sacrifice."

Bergdahl was not cross-examined by the prosecution, only questioned by the defense.

In denying the defense request to dismiss the case, the judge, Col. Jeffery Nance, said Monday that Trump's criticism had not prevented Bergdahl from having a fair sentencing hearing, and that he was "completely unaffected by any comments" about Bergdahl.

However, he added that he will consider Trump's comments as a mitigating factor when he hands down Bergdahl's sentence.

Bergdahl faces life in prison. He was released in 2014 in a prisoner swap arranged by President Barack Obama. The deal was criticized by Trump and other Republicans.

While running for president, Trump disparaged Bergdahl, 31, as a "dirty rotten traitor" and called for him to be executed by firing squad or tossed out of a plane without a parachute.

Nance temporarily halted the sentencing hearing after seeing a video of Trump on Oct. 16 referring to his campaign trail comments in which he said he couldn't talk about Bergdahl, but added, "But I think people have heard my comments in the past."

Related: Bergdahl Hearing Focuses on Soldiers Who Were Hurt Looking for Him

The prosecution hopes to prove that Bergdahl's desertion endangered those who went looking for him, including Mark Allen, the soldier who was shot in the head.

Allen uses a wheelchair and a feeding tube and cannot speak. Shannon Allen told the court that Mark was "always happy-go-lucky" before he was wounded and was an active dad to their son, Cody, and daughter, Journey. She said that he coached baseball and that they planned on having more children.

Now, Shannon said, "his involvement is much more passive."

"He’s present, but he’s not able to have any real physical interaction," she said.

While Allen can make eye contact, laugh, smile and cry, he's unable to express his needs in any way, she continued, adding that she has to guess if he's experiencing a health problem and they often end up in the emergency room.

Shannon Allen, right, wife of Sgt. Mark Allen, leaves the court at Fort Bragg after testifying at the Bowe Bergdahl sentencing hearing. Andrew Craft / The Fayetteville Observer via AP

He can't be left alone, she told the court: "It's like leaving an infant."

Dr. Rafael S. Mascarinas III, a physician at a VA rehab center in Tampa Bay, Florida, where Allen stayed from August 2009 to December 2011, testified that Allen has had multiple surgeries to remove parts of his brain and has had strokes in different parts of his brain.

Shauna Williams reported from Fort Bragg, and Elizabeth Chuck from New York.