(CNN)It must have stuck in President Barack Obama's craw to deliver a win for WikiLeaks.
But that is effectively what he had to do to commute the 35 year sentence of Pvt. Chelsea Manning, who was convicted of committing one of the biggest and most embarrassing leaks of classified information in US history.
The move came with the hours fast running down on Obama's presidency and rocked the political, intelligence and military intelligence establishments in Washington. And it will now rest forever on the 44th President's legacy as one of the most controversial moments of his tenure, judging by the furious bipartisan reaction to his decision to free someone regarded by many in Washington as as a traitor.
His decision to announce the commutation on the eve of his final presidential news conference on Wednesday indicates he wanted to explain the reasons for his decision to the American people in person. That opportunity may go some way to ensuring that the move does not sow controversy at the start of his post-presidency, as Bill Clinton's controversial pardon for fugitive financier Marc Rich did in 2001.
Senior officials told CNN that Obama decided to act because Manning had expressed remorse and responsibility for her actions, and she had already served six years of a long sentence.
Obama may also have been motivated by humanitarian considerations, given that Manning is a transgender woman facing decades in an all-male prison and has attempted suicide several times.
He may also have reasoned that with President-elect Donald Trump about to take office, the chances of Manning winning release for years to come were slim.
The President also came under intense pressure from LGBT groups that have been stalwart supporters throughout his political career to show eleventh hour compassion towards Manning.
A source with knowledge of the White House's thinking told CNN's Gloria Borger that Obama's decision took into account the fact that Manning -- unlike fugitive leaker Edward Snowden -- had pleaded guilty in a court of law to her offenses.
But in many ways, the decision appeared to run counter to some of Obama's own instincts as president and the sensitivity of the political moment.
To begin with, Obama has cultivated a reputation as showing zero tolerance to leakers of classified secrets during his administration.
"We're a nation of laws, we don't make our own individual decision about how the laws operate," Obama told protestors who heckled him over the US government's treatment of Manning at a fundraiser in 2011.
Wikileaks declares 'victory'
Obama's disdain for WikiLeaks itself, which published hundreds of thousands of classified documents stolen by Manning, is well known even though it didn't prevent him, in the end, from showing mercy to Manning.
The whistle-blowing website run by Julian Assange published hundreds of thousands of documents stolen by Manning, including battlefield logs from Iraq and Afghanistan and diplomatic cables that caused deep US embarrassment.
Now, the organization is at the center of the storm over alleged Russian hacking of Democratic servers during the election, and Assange is being accused of directly subverting American democracy.
Obama had sent his then secretary of state, Hillary Clinton, around the world to apologize to US allies for embarrassingly frank disclosures by US diplomats on cables from American embassies to Washington published on the site.
Then Clinton herself, in the eyes of many Democrats, was deprived of the presidency because of the stolen emails from her campaign that were blasted around the world by WikiLeaks during the election.
Military officials are likely to be especially angry about the move, given the fact that they argued the Wikileaks cables and disclosures endangered US service members, diplomats and those who cooperated with them in Iraq and Afghanistan.
It did not take long for WikiLeaks to declare victory over the commutation -- something that could further Obama's public discomfort.
"Victory," Wikileaks said in a series of tweets welcoming the move.
Snowden, who is exiled in Russia and has also been linked to Wikileaks, also congratulated Manning, tweeting "Thanks, Obama."
The political reaction to Manning's impending release from prison -- by May 17 -- was swift and critical.
"Manning stabbed his fellow soldiers in the back by releasing classified information and putting their lives at risk," Republican Sen. Lindsey Graham told CNN's Dana Bash.
"President Obama, by granting clemency to Manning, slapped all those who serve honorably in the face," Graham said.
But Manning's supporters, who have spent years calling on Obama to grant clemency, arguing that her act was motivated by a desire to expose abuses by US troops on the battlefield.
Manning's sentence was "grossly disproportionate, it was far longer than any any that had previously been imposed for offenses related to the leak of sensitive information," Maria McFarland Sanchez-Moreno, of the US division of Human Rights Watch, told CNN International. "The message that was sent by such a long sentence was that people who release classified information even if it is released in the pubic interest, even if it doesn't cause severe harm, will be prosecuted. That could have a chilling effect going forward on other whistleblowers who might have information about abuses, human rights violations, fraud, corruption to disclose."
This story has been updated