Sgt. Bowe Bergdahl is admitting his guilt, bringing an end of sorts to one of the most shameful episodes of President Barack Obama’s tenure.

Bergdahl, who faced an Army court-martial this month, will plead guilty to the two counts with which he’s been charged: desertion and misbehavior before the enemy, the Associated Press reports.

So much for Team Obama’s insistence that Bergdahl had served “with honor and distinction.” Even National Security Adviser Susan Rice’s claim that he’d been “captured on the battlefield” was untrue.

That happy talk — complete with a Rose Garden celebration — was an effort to justify Obama’s decision to purchase then-POW Bergdahl’s freedom by springing five senior Taliban officials from Guantanamo.

Suspicions still run deep that getting those prisoners out of Gitmo was the president’s true goal — since he couldn’t close the prison (as he’d long sought to do) unless he first emptied it out.

Tellingly, Obama failed to notify Congress, as he was legally required to do, before releasing the five.

In 2009, Bergdahl wandered away from his base in Afghanistan after months of discontent. He was quickly captured by the Taliban — triggering a massive manhunt in which several soldiers were seriously wounded.

It’s not known whether the guilty plea is part of a deal with prosecutors, or part of an appeal for mercy (time served, for example) that takes into account the five years Bergdahl spent in brutal captivity.

Bergdahl faces up to life in prison on the misbehavior charge and five years for desertion. Having acted “with deliberate disregard for the consequences of his actions,” as prosecutors charged, a stiff sentence would not be uncalled for.

Sadly, the sentencing won’t be the actual end of this sorry tale: The five Taliban were sent to Qatar for an indefinite stay under house arrest. Yet it’s all too likely that at least some will eventually make it back to the battlefield — and wind up with more American blood on their hands.