SiriusXM is buying Pandora in a $3.5 billion all-stock deal.

The deal will create the world's largest audio entertainment company, the companies said early Monday.

SiriusXM (SIRI) has 36 million subscribers in North America. It was formed with the merger of the Sirius and XM satellite radio services in 2008.

Sirius had paid Howard Stern hundreds of millions of dollars to lure him from traditional radio in 2006. SiriusXM has built a stable of stars with exclusive programming to go along with its lineup of music, news, talk and sports.

Pandora (P), a groundbreaking streaming music service founded in 2000, has more than 70 million active users. It faces intense competition from Spotify (SPOT), from music services offered by Apple (AAPL) and Amazon (AMZN), and from Jay-Z's Tidal, which is partly owned by Sprint (S).

Pandora's ability to stay an independent company was very much in doubt. SiriusXM had already invested $480 million to buy 19% of Pandora's stock last year, and it was widely reported to be looking at a full purchase.

Soon after that investment was announced, Pandora co-founder Tim Westergren lost his positions as CEO and board member, and Michael Herring lost his job as president.

Pandora stock, which was down 35% for the year when they left, has nearly doubled since then, partly in anticipation of a purchase. The company still lost $221 million in the first half of the year, although that was down 43% from the first half of 2017.

"We believe there are significant opportunities to create value for both companies' stockholders by combining our complementary businesses," SiriusXM CEO Jim Meyer said in a statement.

Shares of SiriusXM stock closed down about 10% on Monday. Pandora stock closed down about 1%.