A decade-long battle over copied code in Google's Android operating system has ended in the US Supreme Court.
Oracle, another tech titan, had sued Google in 2010 for copyright infringement over what it said was copied computer code.
Android is now used in an estimated 70% of global smartphones, and damages could have run into the billions.
But the Supreme Court let Google off the hook, overturning a lower court's decision it had infringed copyright.
The court ruled six to two in favour of Google.
At issue was whether Google's use of Oracle's Java API - a widely-used "building block" for programmers - counted as "fair use" under US copyright law.
If it was, the fact that Google was accused of copying more than 11,000 lines of code would not matter.
Justice Stephen Breyer, in his written opinion, said that "to allow enforcement of Oracle's copyright here would risk harm to the public".
So many programmers used and had deep knowledge of Oracle's building blocks that such a move would turn computer code into "a lock limiting the future creativity of new programs".
"Oracle alone would hold the key," he warned.
Oracle made clear that it firmly disagreed with the court's judgement, saying that it had increased Google's power further and damaged other companies' ability to compete.
"They stole Java and spent a decade litigating as only a monopolist can," said Dorian Daley, the company's general counsel, in a statement.
"This behaviour is exactly why regulatory authorities around the world and in the United States are examining Google's business practices."
Google, meanwhile, painted the decision as a victory for the software industry as a whole.
"Today's Supreme Court decision in Google v Oracle is a big win for innovation, interoperability and computing," wrote Ken Walker, the company's senior vice president for global affairs.
"Thanks to the country's leading innovators, software engineers and copyright scholars for their support."
The majority of judges agreed that Google's copying of the Java code - in the particular way it was used - was "a fair use of that material".
But the judges disagreed on how to apply traditional copyright law to computer code.
Justice Breyer, writing for the majority, acknowledged that it is "difficult to apply traditional copyright concepts in that technological world".
But in a dissenting opinion, Justice Clarence Thomas wrote that allowing fair use simply because it allows new products to be created effectively redefines the idea.
"That new definition eviscerates copyright," he warned.
He also lamented that the majority had decided not to rule on whether code was copyrightable, instead saving the question for another day and relying on fair use instead.
"The majority cannot square its fundamentally flawed fair-use analysis with a finding that declaring code is copyrightable," he wrote of his peers.