A man once considered one of Sweden's most prolific serial killers has been released.
The move came after the authorities ruled that his eight murder convictions were based on false confessions.
Sture Bergwall, now 63, has been held in psychiatric detention for more than 20 years.
He confessed to more than 30 killings over three decades and was convicted of eight.
He retracted his confessions six years ago, saying that when he made them he was heavily medicated and seeking attention.
All of his convictions, handed down in a series of trials between 1994 and 2001, were overturned after prosecutors said they had no other evidence linking him to the deaths, some of which may not even have been murders.
"He has been detained for 20 years in a locked psychiatric clinic. It is a miscarriage of justice," his lawyer Thomas Olsson said.
After his convictions were quashed, Mr Bergwall was still kept at the mental institution until a court could decide whether his mental health was good enough to free him.
Now a court in Falun in central Sweden has ruled that although he still suffered from a personality disorder and should continue to receive psychiatric care, he no longer needed to be held in a secure unit.
The case has gripped Sweden for years and the government launched a commission of inquiry last November into possible failings in the legal system that may have resulted in Mr Bergwall's convictions.
His lawyer said Mr Bergwall will now start looking at whether to seek damages.