As the clock winds down on his presidency, President Obama has commuted the sentence of Chelsea Manning, the army intelligence analyst convicted of leaking hundreds of thousands of US diplomatic and military documents to WikiLeaks.

Manning told Adrian Lamo, an ex-hacker and confidant, that she hoped her leak would spark “worldwide discussion, debates and reforms.”

“If not,” she added, “then we’re doomed as a species.”

Make no mistake: Manning was neither an altruistic liberal nor free-speech warrior: She was a narcissist and would-be tyrant who believed rules did not apply to her. She was not motivated by a desire to expose wrongdoing, for she ignored channels used by generations of whistleblowers and instead sought the wholesale exposure of ­government secrets.

Diplomats are like journalists, doctors and lawyers: their jobs depend on the trust and confidentiality of those with whom they speak. As the US military engages increasingly in civil affairs, soldiers are not much different.

Manning not only burned the sources of hundreds of diplomats, but she effectively dissuaded foreigners from trusting any future American official.

The exposure may also have cost lives: Both al Qaeda and the Taliban combed through documents to identify those cooperating with the United States.

WikiLeaks — the chief beneficiaries of Manning’s crime — didn’t care.

WikiLeaks founder Julian Assange suggested those murdered as a result deserved their fate.

“We are not obligated to protect other people’s sources,” he said, adding that Afghans “should know about” those who have engaged in “genuinely traitorous” acts, such as talking to the US military.

Just as turning his back on the “no chemical weapons” red line in Syria convinced the Syrian government and other rogue regimes that they could massacre civilians without consequence, Obama’s willingness to free Manning will convince the disgruntled and unstable that they can betray the trust put in them.

Obama entered office promising to preside over the most transparent administration in US history but led its most opaque. Manning’s commutation does not change this legacy. Rather, it rationalizes treason and reflects Obama’s disdain both for the bureaucracy over which he presided and those who abided by its rules and placed meaning in their oaths.

Michael Rubin, a former Pentagon official, is a resident scholar at the American Enterprise Institute.