Google has won a major US court battle with software firm Oracle after a jury ruled it did not unfairly appropriate parts of the Java programming language.
Oracle had argued that Google had infringed its copyright and had sought nearly $9bn (£6bn) in damages.
The outcome was eagerly awaited by software developers who feared that a victory for Oracle might encourage more such legal actions.
The company says it will appeal against the decision.
Google uses Java in its Android smartphone operating system which powers about 80% of the world's mobile devices.
The company had argued that extending copyright protection to pieces of code called APIs (application programming interfaces) would threaten innovation.
The jury in San Francisco agreed that copyright law allowed "fair use" of the Java elements as they were only a part of a larger system Google had created for a new purpose.
"Today's verdict that Android makes fair use of Java APIs represents a win for the Android ecosystem, for the Java programming community, and for software developers who rely on open and free programming languages to build innovative consumer products," a Google spokesperson said in an emailed statement.
The legal battle began in 2010 and the two firms first faced each other in court in May 2012. A federal judge ruled against Oracle, but the company then appealed. After legal wrangling, the case was sent back to court.
Despite Thursday's outcome, Oracle lawyer Dorian Daley said it would pursue the matter further.
"We strongly believe that Google developed Android by illegally copying core Java technology to rush into the mobile device market," he said.
"Oracle brought this lawsuit to put a stop to Google's illegal behaviour. We believe there are numerous grounds for appeal and we plan to bring this case back to the federal circuit on appeal."