President Obama commuted the 35-year prison sentence of Chelsea Manning, an Army private convicted of taking troves of secret diplomatic and military documents and disclosing them to WikiLeaks, after deciding that Manning had served enough time.

Obama also granted a full and complete pardon to retired ­Marine Gen. James E. Cartwright, a former vice chairman of the Joint Chiefs of Staff who had pleaded guilty to lying to the FBI in an investigation of a leak of classified information about a covert U.S.-Israeli cyberattack on Iran’s nuclear program.

The president’s dramatic, last-minute clemency actions for Cartwright and Manning were surprising for an administration that has brought more leak prosecutions than all previous ones combined. Obama took office pledging to bring a new era of transparency to government, but during his eight years, his administration has presided over at least nine leak cases.

But officials said the president thought that in Manning’s case, seven years behind bars was enough punishment and that she had been given an excessive sentence — the longest ever imposed in the United States for a leak conviction. The administration has contrasted her case with that of Edward Snowden, the National Security Agency contractor who leaked classified documents in 2013 and then fled the country, pointing out that Manning did not try to avoid facing the U.S. justice system for her crimes.

“Chelsea Manning is somebody who accepted responsibility for the crimes she committed,” a senior White House official said, speaking on the condition of anonymity under ground rules set by the White House. “She expressed remorse for committing those crimes. She began serving the sentence that was handed down. The president’s concern was rooted in the fact that the sentence handed down is longer than sentences given to other individuals who committed comparable crimes.”

[How do presidential pardons and commutations work?]

Republicans immediately blasted the White House’s decision, saying the commutation would encourage others to leak sensitive documents.

“This is just outrageous,” House Speaker Paul D. Ryan (R-Wis.) said. “Chelsea Manning’s treachery put American lives at risk and exposed some of our nation’s most sensitive secrets. President Obama now leaves in place a dangerous precedent that those who compromise our national security won’t be held accountable for their crimes.”

President-elect Donald Trump’s team did not respond to requests for comment on the case.

Also on Tuesday, Obama granted clemency to more than 200 low-level drug offenders who were sentenced under harsh laws and would have received lighter sentences if convicted today. In all, the president commuted the sentences of 209 individuals and pardoned an additional 64. He is expected to grant more commutations before he leaves office.

Since 2014, Obama has commuted 1,385 sentences, more than the previous 12 presidents combined. Of those, 540 low-level drug offenders had been serving life sentences.

This “final set of actions” as Obama leaves office “is a signal to the system that prosecutors have gone too far,” said Steven Aftergood, a national security and transparency expert at the Federation of American Scientists.

Manning, 29, will be set free in four months, on May 17, instead of in 2045, under the terms of Obama’s commutation.

The Pentagon did not make the recommendation to the White House to commute Manning’s sentence, and senior Defense Department leaders opposed the move, said defense officials who spoke on the condition of anonymity to discuss internal deliberations.

White House officials said the president’s decision had nothing to do with a recent pledge by WikiLeaks founder ­Julian ­Assange that he would agree to be extradited to the United States if Manning’s sentence was commuted.

“Thank you to everyone who campaigned for Chelsea Manning’s clemency,” read a statement attributed to Assange on the WikiLeaks Twitter feed. “Your courage & determination made the impossible possible.”

Trump invoked the death penalty in 2010 after WikiLeaks’ disclosures, in stark contrast to his refusal to criticize Assange and WikiLeaks for the dissemination of hacked Democratic Party emails last year.

Members of Assange’s legal team did not immediately respond to requests for comment on whether Assange would now agree to be extradited.

“President Obama’s decision was both compassionate and amply justified,” said Elizabeth Goitein, co-director of the liberty and national security program at the Brennan Center for Justice. “Manning’s sentence was orders of magnitude greater than any sentence previously imposed for leaking classified information to the media.”

Manning was arrested in Iraq in May 2010 after she transmitted documents to WikiLeaks that came to be known as the Iraq and Afghanistan “War Logs.” She also shared a video that showed a U.S. Apache helicopter in Baghdad opening fire on a group of people that the crew believed to be insurgents. Among the dead were two journalists who worked for Reuters. She also leaked documents pertaining to Guantanamo Bay prisoners, as well as 250,000 State Department cables.

In an impassioned statement last year accompanying her petition for clemency, she accepted “full and complete responsibility” for disclosing the material. She said she pleaded guilty without the benefit of a plea agreement because she believed that the military justice system would understand her motivation for the leak and sentence her fairly. “I was wrong,” wrote Manning, who is incarcerated at the all-male Fort Leavenworth prison in Kansas.

She said the 35-year penalty was “far more” than she imagined possible — “unreasonable, outrageous and out of line with what I had done.”

[Bradley Manning comes out as transgender: ‘I am a female’ ]

Manning, formerly known as Bradley Manning, came out as transgender after her conviction. She said in her statement last fall that the three years since she had been sentenced had enabled her to reflect on her actions and her struggle to adjust to the military.

“I am not Bradley Manning,” she said. “I really never was. I am Chelsea Manning, a proud woman who is transgender and who, through this application, is respectfully requesting a first chance at life.”

Her reason for passing the documents to WikiLeaks was to raise public awareness about issues she found troubling, including the effect of war on innocent civilians, her attorney, Vincent J. Ward, said in a letter accompanying Manning’s petition. Ward said Manning’s sentence exceeds even international legal norms.

Manning was kept in solitary confinement for almost a year before formal charges were brought, an experience she has called “humiliating and degrading.” The United Nations special rapporteur on torture called her treatment “cruel, inhuman and degrading.”

She has tried to kill herself twice while at Fort Leavenworth — the first time in July 2016 and again in November. After the July attempt, she was placed in solitary confinement as punishment.

“The family is delighted to hear the news, and we are looking forward to seeing Chelsea in May, and we want to thank President Obama for granting her request. We’re all very, very happy about it,” said Debbie, an aunt of Manning’s in Maryland, who asked that her last name not be used to protect her privacy.

Cartwright, a retired four-star Marine Corps general, served as the nation’s second-ranking military officer and was facing his sentencing in two weeks after pleading guilty in October to a felony count of lying to the FBI in a classified leak investigation. He admitted to falsely telling investigators that he did not confirm classified information to reporters writing about a covert U.S.-Israeli cyberattack on Iran’s nuclear program.

The senior White House official said Cartwright’s long history of distinguished service to the nation factored into Obama’s decision. The official said a journalist involved in the case testified that Cartwright did not tell the journalist anything that the reporter did not already know. The conversation was “focused on preventing the publication of information that could be damaging to our national security,” the official said.

When the president is making clemency decisions, “motive matters,” the official said. “It’s clear in this case that based on what the journalist has said . . . that General Cartwright’s motive was different than most of the people who are accused of leaking classified information to a journalist.”

In a statement Tuesday, Cartwright thanked Obama.

“With the greatest pride, I have served my country as a member of the military for more than forty years. This action allows me to continue that work as a private citizen,” he said. “I love this country and believe it to be the greatest nation on earth. I have never lost faith in that belief.”

Julie Tate, David Nakamura, Spencer Hsu, John Wagner and Missy Ryan contributed to this report.

Read more:

Here are the others who received pardons and commutations from Obama

How do pardons and commutations work?