FORT BRAGG, N.C. (AP) — In an unexpected and emotional statement, Army Sgt. Bowe Bergdahl apologized in court Monday to all the military personnel who were wounded searching for him and described the nightmares and flashbacks he experienced during five years in captivity of Taliban allies.

gettyimages 865358348 On Stand, Bergdahl Says Sorry To Those Wounded While Searching For Him

FORT BRAGG, NC – OCTOBER 23: U.S. Army Sgt. Robert Bowdrie ‘Bowe Bergdahl’ (R), 31 of Hailey, Idaho, is escorted into the Ft. Bragg military courthouse for his sentencing hearing on October 23, 2017 in Fort Bragg, North Carolina. Bergdahl pled guilty to desertion and misbehavior of in front of the enemy stemming from his decision to leave his outpost in 2009, which landed him five years in Taliban captivity. (Photo by Sara D. Davis/Getty Images)

Bergdahl was the first witness in what’s expected to be a multi-day presentation by the defense to the judge who will decide his punishment for endangering comrades by walking off his post in Afghanistan in 2009. He spoke for two hours, giving a wide-ranging description of his brutal years in captivity and what challenges he still faces with daily life.

“I would like everyone who searched for me to know it was never my intention for anyone to be hurt, and I never expected that to happen,” he said, choking up at times. “My words alone can’t take away their pain.”

Bergdahl faces a maximum of life in prison after pleading guilty to desertion and misbehavior before the enemy.

His appearance on the witness stand, which the defense hadn’t publicly made known in advance, served as a dramatic counterpoint to several days of emotionally wrenching testimony by several service members who were seriously wounded during a massive search effort. He described the brutal conditions he faced, including beatings with copper wire and unending bouts of gastrointestinal problems brought on by squalid conditions. He was kept in a cage for four out of the five years after several escape attempts, and his muscles atrophied to the point he could barely stand or walk.

Asked by a defense attorney what the worst part of captivity was, he responded that it wasn’t the beatings.

“The worst was the constant, just the constant deterioration of everything. The constant pain from my body falling apart. The constant screams from my mind,” he said, haltingly. “It was the years of waiting to see whether or not the next time someone opens the door if that would be the person coming to execute you.”

(© Copyright 2017 The Associated Press. All Rights Reserved. This material may not be published, broadcast, rewritten or redistributed.)