After two years of sometimes tense negotiations, Universal Music Group has reached a long-term deal to have its songs streamed on Spotify, The Post has learned.

The deal between the largest music label and the No. 1 music streamer was reached recently and is only waiting for the chief executives of both companies to sign off on it, several sources confirmed.

The deal is crucial for Spotify, with 50 million paid subscribers worldwide, as it puts the company, currently valued at $8.5 billion, on a firmer track to go public in 2018.

Universal and Spotify had been operating on a month-to-month basis.

The deal was a long time coming because Spotify had been looking to increase its profitability by convincing labels to take a smaller bite out of its revenue stream.

Under current deals, recorded music companies take 55 percent of Spotify revenue — while music publishers take another 10 percent to 12 percent.

Music labels hadn’t wanted to roll back fees without getting something in return. It is believed that Spotify was successful at winning a lower-revenue take by Universal — but only if it hits certain paid-subscriber growth targets.

In return for retaining a larger slice of revenue, Spotify will give Universal more say in which artists’ new releases are kept off the streamer’s free tier.

Artists such as Taylor Swift, distributed by Universal, had said they were unhappy about the music being given away for free.

Spotify may have been successful in winning a lower revenue take by Universal because it offers labels a well-established independently owned streamer that pays hundreds of millions of dollars to the labels each year — while other players are dominated by Silicon Valley tech companies.

Record companies get paid a rate of 5 cents per 100 plays. Top streamers such as Ed Sheeran can notch 50.7 million streams in a week.

While Universal is believed to have agreed to take a lower slice of revenues, Sony is yet to yield to Spotify’s desire to receive cut-price royalty rights, sources said.