US 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 commutation reduces Manning's sentence but is not a pardon, which some campaigners had called for.
More on Chelsea Manning
Manning's uncle, Kevin Fox, referring to Chelsea as a man, told the BBC the family was "over the moon".
"It's sooner than we expected - we didn't expect his case even to be looked at for another three or four years," Mr Fox said.
Manning lived for four years as a teenager in Wales. Her Welsh family said in a statement that they were "overjoyed", adding that there would "always be a welcome for her here in Wales".
Manning twice attempted suicide last year at the male military prison where she is being held at Fort Leavenworth, Kansas.
She also went on a hunger strike last year, which she ended after the military agreed to provide her with gender transition treatment.
Mr Obama granted commutation of sentences to 209 individuals and pardons to 64 others, in one of his final acts as president.
Edward Snowden, a former National Security Agency (NSA) contractor who leaked information on mass surveillance programmes before fleeing the US, was not 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's the reaction?
Manning's lawyer, David Coombs, told the BBC the decision 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."
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".
More on commuted sentences
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 Manning's commutation had not been influenced in any way by Mr Assange's offer, and the US justice department has not indicted Mr Assange nor 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 (NSA) leaker has not himself submitted the necessary documents.
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.