From the moment a military judge handed down a 35-year prison term for Chelsea Manning in 2013, President Obama and some administration officials saw the sentence as excessive. “Nuts,” said one person close to Obama.

They said Manning, an Army private charged with disclosing troves of secret files to WikiLeaks, should be punished for her crime. But while Obama, a former law professor, was known for his tough stance on government leakers, he had also advocated for changing America’s often harsh, inconsistent sentencing practices.

Long before Manning’s attorneys submitted a second clemency request in November, Obama had considered the notion of “proportionate sentences” in evaluating the soldier’s case, as he had in decisions to grant clemency to more than 1,300 drug offenders.

The key question for the president was how much time Manning should serve. He and his advisers looked at other government leak cases, which indicated that 35 years was the longest sentence ever imposed for a leak conviction. By the time the second request came in, Manning had served six years, much of that time subjected to harsh treatment and solitary confinement.

In his decision to commute Manning’s sentence, made public this week, Obama knew he would face criticism, the person close to the president said, speaking on the condition of anonymity to discuss internal deliberations. “But he felt strongly it was the right thing to do.”

The 11th-hour announcement was a stunning end to a legal saga that began six years earlier with the arrest of Manning, then a 22-year-old intelligence analyst in Baghdad.

The revelations contained in the more than 700,000 documents Manning provided to WikiLeaks captured worldwide attention, revealing for the first time details of the wars in Iraq and Afghanistan and diplomats’ secret and sometimes snarky reports about the countries where they served. They also rattled American officials, who feared the disclosures would undermine U.S. security and alienate allies.

[Obama commutes sentence of Chelsea Manning, soldier convicted for leaking classified information]

Manning pleaded guilty to most of the charges facing her in a military court and, in 2013, received a lengthy sentence for a series of offenses, including violations of the Espionage Act. Soon afterward, Manning, formerly known as Bradley Manning, announced her intention to live as a woman and requested hormone therapy to begin a gender transition.

On Wednesday, Obama addressed his decision to commute Manning’s sentence, effective May 17, in the final news conference of his presidency. “Let’s be clear: Chelsea Manning has served a tough prison sentence,” he said.

“It made sense to commute — and not pardon — her sentence,” he continued. “I feel very comfortable that justice has been served and that a message has still been sent.”

Obama’s announcement adds to the list of executive actions opposed by President-elect Donald Trump, who takes office Friday.

“It sends a very troubling message when it comes to…