President Barack Obama has commuted Chelsea Manning’s sentence for leaking documents to Wikileaks in 2010.
The 29-year-old transgender US Army private, born Bradley Manning, will be freed on 17 May instead of her scheduled 2045 release.
She was sentenced to 35 years in 2013 for her role in leaking diplomatic cables to the anti-secrecy group.
The leak was one of the largest breaches of classified material in US history.
The White House had suggested in recent days it was open to commuting Manning’s sentence.
She twice attempted suicide last year at the male military prison where she is being held at Fort Leavenworth, Kansas.
Manning also went on a hunger strike last year, which ended after the military agreed to provide her with gender dysphoria treatment.
In one of his final acts as president, Mr Obama granted commutation of sentences to 209 individuals and pardons to 64 others.
However, Edward Snowden, a former National Security Agency (NSA) contractor who leaked information on mass surveillance programmes before fleeing the US, will not be granted a pardon.
Russian authorities said on Wednesday that Mr Snowden had been granted a two-year extension to his temporary asylum in the country.
Why Manning? Rajini Vaidyanathan, BBC News
Chelsea Manning’s case divided public opinion in the US. To some she was a whistleblower who lifted the veil on US military secrets. More than 100,000 people signed a White House petition calling for her release and the campaign for her commutation was well publicised. But to others Manning was a traitor who compromised the safety of US military personnel.
House Speaker Paul Ryan described President Obama’s commutation as treachery. When I attended Manning’s sentencing in 2013, the prosecution asked for a tougher sentence than the 35 years handed down. They said they wanted to send a message to future potential leakers.
The White House has yet to explain why it made the decision to free Manning. It’s worth noting that Mr Obama was accused of waging a war on whistleblowers for prosecuting more people under the Espionage Act than any other US president before him.
What has been the reaction?
Manning’s lawyer, David Coombs, told the BBC the commutation would be a great relief to his client.
“It really is a great act of mercy by President Obama,” said Mr Coombs. “For myself and Chelsea, I’m very thankful he took that option.”
Journalist Glenn Greenwald, who broke the story of Edward Snowden’s leaks, told the BBC: “I don’t think she (Manning) should have spent a single day in prison.”
He said she was “heroic and has inspired millions of people around the world”.
But Republican Senator John McCain said the president’s decision was “a grave mistake that I fear will encourage further acts of espionage”.
And House Speaker Paul Ryan said it was “just outrageous”, adding that the US Army private had “put American lives at risk”.
What was in the leaked cables?
The US Army charged Manning with 22 counts relating to the unauthorised possession and distribution of more than 700,000 secret diplomatic and military documents and video.
Included in those files was video footage of an Apache helicopter killing 12 civilians in Baghdad in 2007.
Manning also passed on sensitive messages between US diplomats, intelligence assessments of Guantanamo detainees being held without trial and military records from the wars in Iraq and Afghanistan.
The disclosures were considered an embarrassment to the US, prompting the Obama administration to crack down on government leaks.
At a sentencing hearing, Manning apologised for “hurting the US” and said she had mistakenly thought she could “change the world for the better”.
What next for Julian Assange?
Wikileaks, the anti-secrecy organisation which published the diplomatic cables, has previously said its founder Julian Assange would agree to be extradited to the US if Mr Obama granted clemency to Manning.
The White House said the Manning commutation was not influenced in any way by Mr Assange’s extradition offer.
Mr Assange, who has taken refuge in the Ecuadorian embassy in London since 2012, did not immediately comment on whether he plans to surrender.
But he did tweet: “Thank you to everyone who campaigned for Chelsea Manning’s clemency. Your courage & determination made the impossible possible.”
The US justice department has not publicly announced any indictment against Mr Assange. It is Sweden that has sought to extradite him, for an alleged sex crime.
Why no pardon for Edward Snowden?
More than a million supporters of Mr Snowden have petitioned President Barack Obama to pardon him.
But according to the White House, the National Security Agency leaker has not himself submitted the necessary documents for clemency.
In November, Mr Obama told German newspaper Der Spiegel: “I can’t pardon somebody who hasn’t gone before a court and presented themselves.”
The White House last week pointed out that Manning had passed through the US military justice system and acknowledged her crimes.
Mr Snowden, however, fled the US in 2013, evading charges in America which could put him in prison for up to 30 years.
White House spokesman Josh Earnest said “the disclosures by Edward Snowden were far more serious and far more dangerous”.
He had also “fled into the arms of an adversary and has sought refuge in a country that most recently made a concerted effort to undermine the confidence in our democracy”, Mr Earnest added.
How do pardons and commutations work?
Mr Obama has commuted 1,385 sentences and issued 212 pardons, more than the total granted by the past 12 presidents combined.
In America, a pardon not only lifts the sentence but removes other penalties such as the bar on convicted felons sitting on federal juries, and state-level prohibitions on such things as voting or possession of firearms.
A commutation means the sentence is lifted but the civil handicaps outlined above remain.
Neither a pardon nor a commutation is an acknowledgment of innocence.