YouTube’s young founders may have been the biggest beneficiaries of last week’s $1.65 billion deal with Google, but they have some unexpected bedfellows — old-line media companies that had been considered YouTube’s biggest legal threat.

Three of the four major music companies — Vivendi’s Universal Music Group, Sony and Bertelsmann’s jointly owned Sony BMG Music Entertainment, and the Warner Music Group — each quietly negotiated to take small stakes in YouTube as part of video- and music-licensing deals they struck shortly before the sale, people involved in the talks said yesterday. The music companies collectively stand to receive as much as $50 million from these arrangements, these people said.

Because a significant portion of the videos posted to YouTube contain copyrighted songs or video material, the Web site had been considered a litigation land mine. Last month, Doug Morris, the chief executive of the Universal Music, called YouTube and MySpace “copyright infringers” and said the sites “owe us tens of millions of dollars.”

Just this week, Universal filed suits against Bolt and Grouper, two smaller video-sharing sites, for allowing users to post hundreds of pirated music videos of its artists, including Mariah Carey, 50 Cent and the Black Eyed Peas.