CUPERTINO, Calif. — Apple, the company that turned digital music into a mainstream phenomenon, said on Wednesday that it was buying Beats Electronics, a rising music brand, for $3 billion, in a move that will help it play catch-up with rivals that offer subscription-based music services.

Apple and Beats executives said the companies would work together to give consumers around the world more options to listen to music. The Beats brand will remain separate from Apple’s, and Apple will offer both Beats’s streaming music service and premium headphones.

Apple said iTunes, which sells individual songs and albums and offers a streaming radio service, would be offered alongside the Beats music service.

The Beats deal brings Jimmy Iovine, a longtime music executive, and Dr. Dre, the rapper, to work under Eddy Cue, Apple’s executive in charge of Internet services. Dr. Dre and Mr. Iovine, who founded Beats in 2006, join a list of prominent executives whom Apple has added to its roster, including Angela Ahrendts, the former chief of Burberry, and Paul Deneve, the former chief of Yves Saint Laurent.