The man who stabbed to death Swedish foreign minister Anna Lindh had his life sentence thrown out by an appeals court and will be confined for treatment of psychiatric problems.

The Svea Court of Appeal agreed on Thursday that Mijailo Mijailovic suffered from "borderline personality disorders."

With the ruling, he'll be moved from prison to the forensic psychiatry ward at the Huddinge hospital. Where he will spend the rest of his confinement – which will likely last for the rest of his life – will be decided later.

Mijailovic's lawyer, Peter Althin, argued that his client didn't intend to kill Lindh when he saw her shopping and stabbed her.

The 25-year-old was under the influence of a cocktail of antidepressant drugs at the time, and Althin said voices in Mijailovic's head, including Jesus, urged him to attack.

The judges took into account the testimony of mental health experts who agreed Mijailovic is mentally ill, but they differed on whether he knew what he was doing.

"It is clear that Mijailovic, especially after the knife attack against Anna Lindh, acted very rationally and coolly," the court said in its ruling. "Even so, if Mijailovic 'heard voices' at the time, clearly he was not governed by them."

Chief prosecutor Agneta Blidberg didn't say if she would appeal the decision of the five-judge panel to the Supreme Court.

Mijailovic admitted that he stabbed Lindh last September. He was convicted of murder in March and sentenced to life in prison.

The murder rattled a country where public officials have been accustomed to moving about in public with little or no security.

Lindh was a popular politician who many thought would become prime minister.

The country of nine million, which still had bitter memories of the 1986 killing of Prime Minister Olof Palme, went into mourning after her killing.