Image copyright YouTube Image caption Screenshots of the new YouTube Music app

YouTube is launching a music streaming service, offering both videos and audio tracks, in an attempt to compete with the likes of Spotify and Apple Music.

YouTube Music will combine millions of "official" tracks with the vast catalogue of rarities and remixes uploaded by YouTube's users.

Like Spotify, it will offer a free, ad-funded app, alongside premium subscriptions costing $9.99 per month.

It will launch in five countries, including the US and Mexico, on 22 May.

The Google-owned company said YouTube Music would come to Europe "soon".

Personalised playlists

YouTube Music product manager Elias Roman said: "The days of jumping back and forth between multiple music apps and YouTube are over. Whether you want to listen, watch or discover, it's all here."

In a blog post, he added that the service would offer a mix of "official songs, albums, thousands of playlists and artist radio plus YouTube's tremendous catalogue of remixes, live performances, covers and music videos that you can't find anywhere else".

He promised that the new app would offer personalised playlists based on users' streaming history, much like Spotify's Discover Weekly.

It is understood that YouTube Music will eventually replace Google Play Music, which is the company's current streaming offering.

Existing Google Play Music customers will get a YouTube Music package thrown into their subscription for free, while Roman reassured users that their playlists, purchases and uploads would remain intact once Google Play was phased out.

Image caption Some of the biggest-selling artists of last year

YouTube is already the most popular platform for streaming music in the world (excluding China) - accounting for 46% of all listening.

Although the site attracts more than a billion music fans every month, it has repeatedly been attacked by the music industry for allowing users to upload videos that infringe on copyright, and for failing to pay artists properly.

The new service is evidence of a rapprochement between Google and the music industry, and new licensing deals were negotiated last year.

Although more than one billion people stream music on YouTube every month, the Google-owned company lags behind its competitors when it comes to paid-for subscriptions.

Launching in five territories

Its current offerings - Google Play and YouTube Red - reportedly have a combined user base of seven million paying customers.

Spotify currently has 75 million subscribers, while Apple Music has 42 million, with a further eight million taking advantage of its free three-month trial.

The five territories where YouTube Music will launch are the US, Australia, Mexico, South Korea and New Zealand.

Not by coincidence, these are the countries where YouTube Red - a subscription service offering original programmes and videos - already exists.

That service will soon be re-branded YouTube Premium, which will include access to all YouTube Originals as well as YouTube Music for $11.99 a month. The price paid by current YouTube Red subscribers won't change.

Follow us on Facebook, on Twitter @BBCNewsEnts, or on Instagram at bbcnewsents. If you have a story suggestion email entertainment.news@bbc.co.uk.