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.
What has the reaction been like?
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.
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".
Writing on Twitter, Mr Snowden said: "Let it be said here in earnest, with good heart: Thanks, Obama," he said.
But Republican Senator John McCain said the decision was "a grave mistake that I fear will encourage further acts of espionage".
And House Speaker Paul Ryan, also a Republican, called it "outrageous".
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 thought she could "change the world for the better".
What next for Julian Assange?
Wikileaks, which published the diplomatic cables, 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, and the US justice department has not indicted Mr Assange or publicly sought his extradition.
He is wanted for questioning by Swedish authorities in relation to an alleged sex offence.
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 and determination made the impossible possible."
Why no pardon for Edward Snowden?
More than a million supporters of Mr Snowden have petitioned Mr Obama to pardon Mr Snowden, who also leaked classified US documents.
But according to the White House, the National Security Agency leaker has not himself submitted the necessary documents for clemency.
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. He now lives in Russia.
White House spokesman Josh Earnest said "the disclosures by Edward Snowden were far more serious and far more dangerous" and accused him of fleeing "into the arms of an adversary".
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.
(Published by BBC - January 18, 2017)