The tech giant did not disclose the size of the deal, though early reports of the acquisition last week estimated the price tag at $400m (£299m).
Shazam lets users identify songs by pointing a smartphone or tablet at speakers playing music.
It is already used by Apple's Siri service to help users identify the music playing on their iPhones.
Apple said Shazam would be a "natural fit" with its Apple Music streaming service and would help users discover new songs.
The service has 27 million users and competes with Spotify, which has 60 million.
Digital services are increasingly important to Apple as iPhone sales slow.
The latest deal is its biggest acquisition in the music industry since paying $3bn (£2.25bn) for Beats Electronics' line of headphones and music service in 2014.
Shazam was founded in 2002 and made one of the first apps for the iPhone.
It has about 250 employees at its London headquarters and seven other offices in the US, Australia and Germany.
Apple said Shazam's team would be joining it.
Tom Neumayr, spokesman for Apple, said Shazam "is used by hundreds of millions of people around the world, across multiple platforms".
He added: "We have exciting plans in store, and we look forward to combining with Shazam upon approval of today's agreement."
The reported $400m price for Shazam falls short of a recent $1bn valuation for the privately-held company.