Bowe Bergdahl compared his first year in Taliban captivity — starved, stinking and chained to a bed — to being tossed in a closet and forgotten.

“Picture someone taking a bag, throwing it into the closet, shutting the door and just forgetting about it. That was basically how they treated me,” he said.

In the third episode of the popular podcast “Serial,” which is focused on Bergdahl’s alleged desertion from the Army in 2009 and subsequent five-year captivity by the Taliban, he details the misery of his first year held hostage — ending in a dramatic escape attempt that lasted 8½ days.

The interview was conducted by filmmaker Mark Boal (“The Hurt Locker,” “Zero Dark Thirty”) as part of a project on Bergdahl’s life. He lent the recordings to “Serial,” which is hosted by Sarah Koenig.

Bergdahl said he saw his first chance at escape soon after his abduction in Afghanistan’s eastern Paktika province, when a water delivery temporarily distracted his captors. He managed to slip off the chains binding his hands and feet and unlatched the flimsy wire holding the door to his cell closed.

He was free for only 15 minutes, running barefoot over rocks and climbing onto a roof and covering himself in mud to hide, he said in audio used by the podcast. He was caught in moments and hauled back into his cell, where men beat him with a rubber hose. They then blindfolded him and moved him to a new home, in what he now believes was North Waziristan in Pakistan, he said.

His new living arrangements were filthy and painful.

“In the new place, they put me on an Afghan bed and they chained my feet to the ends of the bed and chained my hands to the tops of the bed so that basically I was spread-eagle on the bed and blindfolded. And that’s how I spent the majority of the next three months,” he said.

He was allowed to use the bathroom twice a day and could shower around once a month. He developed bedsores and chronic diarrhea as a result.

“The time deprivation, too much light or too much darkness and too much randomness, it just wears away at you and drives your nerves into the ground. The constant worry ‘Am I going to die today?’ or is something worse going to happen,” he said.

Although watching over Bergdahl was a high honor, the guards were often bored and would pass the time by making videos of him, interrogating him with ridiculous questions or shaving his beard into shapes they found amusing, he said.

“They ask you, is Obama gay and sleeps with men?” he recalled. His young guards were also curious about where US military bases got their prostitutes, alcohol and drugs, and were obsessed with American soft drinks, he added.

“They love Mountain Dew. If you want to piss people off in that country, all you do is cut off their sugar supply,” he said.

Eventually, Bergdahl was moved to what he described as a wooden fortress and placed in a cell with an open window. By that time he had managed to squirrel away a few objects — an 8-inch piece of PVC pipe, a random key, an empty soda bottle, a nail and a wooden slat — from which he was able to hatch his next escape plan.

“I practiced all the nights before, counting the hours down until everything was silent so I knew everyone was asleep,” he said.

He shimmied from his window down a rope made from bedding and the chains he’d removed from his hands and feet. When he hit the ground, it was like a weight had been lifted from his shoulders, even though he knew the road to safety would be perilous.

‘Picture someone taking a bag, throwing it into the closet, shutting the door and just forgetting about it. That was basically how they treated me.’ - Bowe Bergdahl

“I had to basically come to terms with the fact that this was very much like a suicide mission — one way out and I was searching for a needle in a haystack as far as being saved,” he said.

The darkness would be his downfall.

A few hours into his journey, he accidentally stepped off a cliff in the dark and badly injured his left side. Unable to walk, Bergdahl crawled across the rural, hilly landscape and tried to stay hidden in shelters made of sticks for the next week. To survive, he ate a few blades of grass and drank filthy water.

Sick and starving, he recalled the anguish of seeing American drones pass overhead at night but having no way to contact them.

“I’d seen like six drones moving across the sky. It’s not a nice feeling you’re so close but things are so stacked against you, you can’t do anything but keep going,” he said.

The Taliban search team found him on day eight, so frail and sick that they only ripped out some of his hair and beard — as opposed to beating him — as punishment.

Despite the risks, his failed escape plan seemed better than the alternative.

“It was like OK if I’m going to die, either from exposure out there or being shot while I escape, it’s better than having my head cut off because I saw enough of those movies or videos to know what that would be like,” he reasoned.

“That escape was the last time I saw stars since until the night Special Forces picked me up,” he said.