WASHINGTON — President Obama on Tuesday largely commuted the remaining prison sentence of Chelsea Manning, the army intelligence analyst convicted of an enormous 2010 leak that revealed American military and diplomatic activities across the world, disrupted the administration, and made WikiLeaks, the recipient of those disclosures, famous.

The decision by Mr. Obama rescued Ms. Manning, who twice tried to commit suicide last year, from an uncertain future as a transgender woman incarcerated at the male military prison at Fort Leavenworth, Kan. She has been jailed for nearly seven years, and her 35-year sentence was by far the longest punishment ever imposed in the United States for a leak conviction.

Now, under the terms of Mr. Obama’s commutation announced by the White House on Tuesday, Ms. Manning is set to be freed in five months, on May 17 of this year, rather than in 2045.

The commutation also relieved the Department of Defense of the difficult responsibility of her incarceration as she pushes for treatment for her gender dysphoria — including sex reassignment surgery — that the military has no experience providing.

In recent days, the White House had signaled that Mr. Obama was seriously considering granting Ms. Manning’s commutation application, in contrast to a pardon application submitted on behalf of the other large-scale leaker of the era, Edward J. Snowden, the former intelligence contractor who disclosed archives of top secret surveillance files and is living as a fugitive in Russia.

Asked about the two clemency applications on Friday, the White House spokesman, Joshua Earnest, discussed the “pretty stark difference” between Ms. Manning’s case for mercy with Mr. Snowden’s. While their offenses were similar, he said, there were “some important differences.”

“Chelsea Manning is somebody who went through the military criminal justice process, was exposed to due process, was found guilty, was sentenced for her crimes, and she acknowledged wrongdoing,” he said. “Mr. Snowden fled into the arms of an adversary, and has sought refuge in a country that most recently made a concerted effort to undermine confidence in our democracy.”

He also noted that while the documents Ms. Manning provided to WikiLeaks were “damaging to national security,” the ones Mr. Snowden disclosed were “far more serious and far more dangerous.” (None of the documents Ms. Manning disclosed were classified above the merely “secret” level.)

Ms. Manning was still known as Bradley Manning when she deployed with her unit to Iraq in late 2009. There, she worked as a low-level intelligence analyst helping her unit assess insurgent activity in the area it was patrolling, a role that gave her access to a classified computer network.

She copied hundreds of thousands of military incident logs from the Afghanistan and Iraq wars, which, among other things, exposed abuses of detainees by Iraqi military officers working with American forces and showed that civilian deaths in the Iraq war were likely much higher than official estimates.

The files she copied also included about 250,000 diplomatic cables from American embassies around the world showing sensitive deals and conversations, dossiers detailing intelligence assessments of Guantánamo detainees held without trial, and a video of an American helicopter attack in Baghdad in two Reuters journalists were killed, among others.

She decided to make all these files public, as she wrote at the time, in the hope that they would incite “worldwide discussion, debates, and reforms.” WikiLeaks’ disclosed them — working with traditional news organizations including The New York Times — bringing notoriety to the group and its founder, Julian Assange. Read more at NY Times