Oracle had sued Google in 2010, claiming that the firm's Android mobile software infringed both the copyrights and patents it had obtained in the acquisition of Sun Microsystems.
But Judge William Alsup ruled late on Thursday (May 31) that the 37 APIs for the Java programming language used in Android were not covered by copyright, thus clearing Google of infringing Oracle's intellectual property.
"Google has violated no copyright, it being undisputed that Google's implementations are different," Alsup said.
Google welcomed the judgement, saying that it would ensure developers were free to make their code more widely available across multiple software programmes.
"This ruling, if permitted to stand, would undermine the protection for innovation and invention in the US and make it far more difficult to defend intellectual property rights against companies anywhere in the world that simply takes them as their own," the firm said.
In his ruling at a court in San Francisco, Alsup said that he was unable to support Oracle's application as it would restrict innovation in programming.
"To accept Oracle's claim would be to allow anyone to copyright one version of code to carry out a system of commands and thereby bar all others from writing their own different versions to carry out all or part of the same commands," he said. "No holding has ever endorsed such a sweeping proposition."
However, the judge did say that the order "does not hold that Java API packages are free for all to use without licence".
A jury in the case said on May 7 that Google infringed eight of Oracle's APIs, but could not reach agreement on whether Google was covered by "fair use" provisions in US law.
Alsup said that without the jury verdict on that question, California-based Oracle cannot seek damages, estimated at $1bn, from Google.
The same jury had ruled on May 23 that Google's Android did not infringe two Java patents, but it did find that Google infringed Oracle's copyrights for nine lines of codes.
Oracle can seek around $150,000 in statutory damages for that verdict, but the trial has already cost both sides millions in legal fees.
Fresh from its victory over Oracle, Google has raised a regulatory complaint against Microsoft and Nokia, accusing the two firms of illegally feeding mobile patents to a technology 'troll' looking to rake in billions of dollars.
MOSAID feels that the patents could generate licensing fees of around $3 billion over the next decade. But it has been suggested that MOSAID is a 'troll', a term used for a company that earns money from patent royalties instead of innovating in new technology.
Microsoft shrugged off Google's complaint as the 'desperate tactic' of a firm already facing regulatory questions about its dominance of online search advertising.