The deal is worth a total of $3bn (£1.8bn), and is thought to be Apple's largest acquisition to date.
As part of the acquisition, Beats co-founders Jimmy Iovine and Dr Dre will join the technology firm.
Apple boss Tim Cook said the deal would allow the firm to "continue to create the most innovative music products and services in the world".Continue reading the main story “Start Quote
The Beats deal is totally in character for Apple: everyone is puzzled”End Quote Benedict Evans Technology analyst
In a statement, Apple said it is paying an initial $2.6bn (£1.6bn) for Beats, and approximately $400m (£239m) "that will vest over time".
Beats was founded in 2008 by music producer Jimmy Iovine and hip-hop star Dr Dre and until recently was best known for its headphones.
It started a subscription-based music streaming service earlier this year.
Apple has its own iTunes store, the world's largest music download service, and launched iTunes Radio last year.
But despite having been an early pioneer of digital music, the Californian firm has been facing increased competition from subscription services such as Spotify, Pandora and Rdio.Continue reading the main story Analysis Leo Kelion Technology desk editor
There had been speculation that Apple might drastically cut its offer price for Beats or pull the deal altogether, after a video of Dr Dre describing himself as hip-hop's first billionaire leaked online.
But the deal has now been confirmed for only $200m less than what had originally been reported.
The press release announcing the tie-up mentions Beats' "premium sound entertainment," but there has been criticism of its headphones' sound quality.
However, there's no doubting their popularity or the skill of Beats' co-founders Jimmy Iovine and Dr Dre in building up the brand.
It's questionable whether Apple's co-founder Steve Jobs would have been willing to share the limelight with two such outspoken personalities.
But the challenge for the more reserved Tim Cook is to bring the two firms' very different cultures together, and to make the most of the Beats brand, as he delivers on a promise to launch new products this year.
However, Beats' music service only has about 110,000 subscribers, compared with Spotify's 10 million.'It's the people'
The deal with Beats also marks a departure for Apple, which has a reputation for developing new products in-house, rather than buying up smaller firms - a method preferred by rivals Google.
But in an interview with the New York Times, Mr Cook hinted that Beats' founders may have been part of the attraction.
"Could Eddy's team [Eddy Cue, Apple executive in charge of iTunes] have built a subscription service? Of course," he told the newspaper.
"You don't build everything yourself. It's not one thing that excites us here. It's the people. It's the service."
"These guys are really unique," Mr Cook added. "It's like finding the precise grain of sand on the beach. They're rare and very hard to find."
The Apple boss also said that Dr Dre and Mr Iovine would be coming up with "products you haven't thought of yet".Apple released this picture of Beats founders Jimmy Iovine and Dr Dre posing with Mr Cook and Mr Cue 'Everyone is puzzled'
However some analysts remain baffled by the acquisition.
Technology writer Benedict Evans tweeted: "If you think Apple's lost it, Beats deal is confirmation. If you don't, it's? perplexing. Few really convincing rationales."
Beats co-founder Jimmy Iovine, who made his name as chairman of the Interscope Geffen A&M record label, welcomed the deal.
"I've always known in my heart that Beats belonged with Apple," he said.The deal is thought to have made Beats co-founder Dr Dre the first hip-hop billionaire
"The idea when we started the company was inspired by Apple's unmatched ability to marry culture and technology.
Apple analyst Jim Dalrymple hinted that it may be Mr Iovine's talent that the technology firm is after.
Writing on his website The Loop, Mr Dalrymple said: "In my opinion, Jimmy is going to play an important role going forward.
"Maybe not that you always see, but he'll be there".
As well as headphones, Beats sells earphones and portable speakers, and has even developed partnerships with carmakers and computer manufacturers to include its BeatsAudio software technology in their products.
The company's flagship products have also received several celebrity endorsements, with stars including Lady Gaga, Lil Wayne and Nicki Minaj designing their own customised Beats headphones.
Subject to regulatory approvals, Apple said it expects the deal to close in the fourth financial quarter of this year.