Dewani walked free from the Cape Town court immediately after Judge Jeannette Traverso said the state's evidence had "fallen far below" the level needed to secure a conviction.
Prosecutors had said Dewani hired hitmen to kill his 28-year-old Swedish bride Anni in a staged hijacking in Cape Town in November 2010 because he is gay and felt trapped into marriage by family pressures.
Dewani says he is bisexual and loved Anni.
The judge conceded that there were "a number of unanswered questions" about the Cape Town murder and acknowledged "strong public opinion" that Dewani should take the stand.
Traverso also noted a plea by the murdered woman's family that Dewani should not be allowed to walk free without testifying, but said her ruling was based on law and could not be influenced by emotion.
She cited previous cases where it was established that it would be unjust to force the accuse to testify in his own defence simply in the hope that he would incriminate himself.
Dressed in an immaculate suit and tie, with his greying hair cropped short, 34-year-old Dewani stepped out of the dock and greeted his weeping mother and other members of his family.
The murdered woman's family also wept as they left the court in shock.
Both families are of Indian origin and had sat across the courtroom from each other since the trial began in October with graphic video of Anni's body sprawled across the seat of a taxi.
She had been killed with a single shot, execution style, prosecutors said.
Anni's sister told an international media scrum on the steps of the high court: "Justice has failed us."
A small but vocal protest group chanted "Justice for Anni" as her weeping family left, accusing the judge of favouring lawyers hired by the wealthy Dewani family.
The ruling is a blow to the reputation of South Africa's state prosecutors, coming after a lengthy and costly battle to extradite Dewani from Britain after the murder in November 2010.
Dewani's lawyers applied for his discharge at the end of the state's case, arguing that the evidence against him was so weak he should be acquitted.
Traverso agreed, delivering a scathing assessment of key state witnesses.
She said evidence given by taxi driver Zola Tonga that implicated Dewani in a murder plot was "highly improbable," while another prosecution witness was described as a "self-confessed liar".
Tongo and one of the hijackers — both serving long jail terms for the murder — testified that Dewani hired them for 15,000 rand ($1,300) to kill his new wife.
The taxi driver and Dewani were freed before Anni was driven away and later killed.
Dewani's lawyer Francois van Zyl argued that their evidence was full of contradictions.
According to South Africa's Criminal Procedure Act, an accused can be declared not guilty at the close of the prosecution case if the court feels there is insufficient evidence to show he or she committed the crime.
Dewani returned to Britain within days of the murder in November 2010 and fought a three-year legal battle to avoid being extradited to South Africa, claiming he had mental health problems, including depression and post-traumatic stress.
But he was sent back to South Africa in April, where he was found fit to stand trial and has been held at the Valkenberg psychiatric hospital for the duration of the trial.
He is now expected to leave South Africa as soon as possible.