Apple has got the Beats.

The Cupertino tech giant on Wednesday announced it has struck a $3 billion deal to buy Beats Electronics, which makes high-end headphones, and its sister company, Beats Music, which runs a subscription music service. The deal, the largest in Apple's history, will bring to the company not only new products but also Beats founders Jimmy Iovine and Dr. Dre, both of whom are music industry legends.

Beats will help Apple "continue to create the most innovative music products and services in the world," company CEO Tim Cook said in a statement.

While many analysts questioned the high price of the deal, some said it would give Apple a profitable new product line and potentially renewed cache among younger consumers. It also gives Apple entree into the subscription music business.

The deal comes at a critical point for Apple, which has seen its sales and profit growth slow from rocket-like to a snail's pace in recent years. Sales of the iPhone are growing slower than the broader market and the iPad has actually seen a sales decline. And despite rumors of numerous new products in the works, the company hasn't launched a new product line since unveiling the iPad four years ago.

The deal also comes amid a transition in the music industry. Sales of digital music, which Apple's iTunes music store has long dominated, have started to decline. At the same time, revenue from music subscription services, which Apple has long resisted, have started to rise rapidly.

The acquisition arguably addresses both of those larger issues, providing Apple with new, potentially fast-growing lines of products and establishing it as a player in the subscription music business.

Beats Electronics has two lines of business. The company sells portable speaker systems, headphones and earphones that range in price from $100 to $400. And it licenses its audio software technology to companies, including Hewlett-Packard and Chrysler, to improve the sound quality of their computers and cars.

Launched in January, Beats Music is a streaming music service similar to Spotify, Rdio or Microsoft's Xbox Music. Subscribers pay $10 a month to play any song in Beats' catalog on demand. Where the service tries to distinguish itself is with playlists curated by music experts.

As a private company, Beats does not disclose its financial results. But it reportedly has annual sales of $1.5 billion. The number of subscribers to Beats Music is reportedly in the low hundreds of thousands.

But the deal could also provide Apple some other benefits. Beat's headphone business offers Apple a product line that has better profit margins than many of its current products, said Danielle Levitas, a senior consumer technology analyst with market research firm IDC. That could be important for the company as the margins for its other products come under pressure amid efforts to stay competitive with rivals.

Additionally, the Beats brand likely appeals to a different set of consumers than does Apple, she said. Acquiring Beats could be a way for Apple to reach younger customers than those who buy from iTunes or purchase iPhones. Apple could potentially add the Beats name to its products, she said.

"There's a little bit of the hipness factor," said Levitas. "This probably helps Apple's penetration into Millennials and urban hipsters."

Apple's interest in the Beats Music subscription service is more difficult to understand. Given that it already operates its own streaming music service -- albeit a free one -- in iTunes Radio, the company likely could have created a Spotify rival without having to buy Beats, analysts said. And despite the growing popularity of such services, they haven't proven to be a great business so far. Spotify and Pandora -- the biggest subscription music and Internet radio services -- both lose money.

But Apple could use Beats Music to launch a new kind of streaming service, suggested Mike McGuire, a media analyst at Gartner, a market research firm. One possibility is a subscription service that includes not just music, but also movies and TV shows.

"That's where I think this gets pretty interesting," McGuire said.

Apple is paying $2.6 billion in cash and $400 million in stock for Beats. The companies expect the deal, which is subject to regulatory approval, to close in the third quarter.

Representatives for Apple and Beats did not respond to requests for comment.

Contact Troy Wolverton at 408-840-4285. Follow him at Twitter.com/troywolv.