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.