South African athlete Oscar Pistorius, who faces murder charges over the fatal shooting of his girlfriend, has been granted bail after a four-day hearing.
Magistrate Desmond Nair said the state had not made a case that he would flee, or that he had a violent character.
The Paralympic champion denies murder, saying he shot Reeva Steenkamp thinking she was an intruder at his home.
The next hearing in the case has been set for 4 June. Bail was set at 1m rand (£74,000; $113,000).
He was ordered to hand over his passport, avoid his home in Pretoria and report to a police station between 07:00 and 13:00 every Monday and Friday.
Mr Nair took almost two hours to deliver his judgement.
He criticised the testimony of Detective Hilton Botha for not following up important leads and changing his evidence.
But the magistrate also said he had difficulty understanding why Mr Pistorius had opened fire in the way he did.
However, he said Mr Pistorius had "reached out to meet the state's case" and had given a full version of events at an early stage.
"I come to the conclusion that the accused has made a case to be released on bail," he said.
Mr Pistorius's family and supporters in the court gasped and cheered as the magistrate announced his decision.
His uncle, Arnold Pistorius, said outside court: "We are relieved by the fact that Oscar got bail today, but at the same time, we are in mourning for Reeva Steenkamp and her family."
The hearing began on Tuesday and both prosecution and defence laid out their cases.
Both sides agree that Mr Pistorius shot through the bathroom door four times, hitting and killing Ms Steenkamp.
But prosecutors allege the shooting happened after the couple had an argument at Mr Pistorius's home in the early hours of 14 February.
Det Botha told the court that witnesses had heard shouting, screaming and gunfire from about 600m (2,000ft) away.
But later he changed his evidence to suggest the witnesses were much closer.
And on Thursday it emerged that Det Botha faces allegations of attempted murder, and he was removed from the case.
Mr Pistorius says he woke in the middle of the night, and thought there was an intruder in the bathroom.
The prosecutors sought to portray Mr Pistorius as man with a history of violence who was likely to flee the country.
But the defence argued it would be impossible for Mr Pistorius to flee because his prosthetic legs would be noticed wherever he went.
Ms Steenkamp, 29, was a model and law graduate with a burgeoning television career.
Oscar Pistorius, 26, won gold medals at the 2004 Paralympic Games in Athens, in Beijing in 2008 and London in 2012.
In London he made history by becoming the first double-amputee to run in the Olympics, making the semi-final of the 400m.