WASHINGTON — President Obama on Tuesday commuted all but four months of the remaining prison sentence of Chelsea Manning, the Army intelligence analyst convicted of a 2010 leak that revealed American military and diplomatic activities across the world, disrupted Mr. Obama’s administration and brought global prominence to WikiLeaks, the recipient of those disclosures.

The decision by Mr. Obama rescued Ms. Manning, who twice tried to kill herself last year, from an uncertain future as a transgender woman incarcerated at the men’s 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.

At the same time that Mr. Obama commuted the sentence of Ms. Manning, a low-ranking enlisted soldier at the time of her leaks, he also pardoned James E. Cartwright, the retired Marine general and former vice chairman of the Joint Chiefs of Staff who pleaded guilty to lying about his conversations with reporters to F.B.I. agents investigating a leak of classified information about cyberattacks on Iran’s nuclear program.

The two acts of clemency were a remarkable final step for a president whose administration carried out an unprecedented criminal crackdown on leaks of government secrets. Depending on how they are counted, the Obama administration has prosecuted either nine or 10 such cases, more than were charged under all previous presidencies combined.