The Walt Disney Company has agreed to acquire Comcast’s one-third stake in Hulu and to take full control of the streaming service, the companies said on Tuesday.

The sale price would be at least $5.8 billion and could climb once an independent party assesses Hulu’s fair market value, the companies said. The potential payout is based on Hulu’s current $27.5 billion valuation (last month, it was valued at $15.8 billion).

The sale itself will not happen for at least five years, the companies said. Hulu’s valuation will most likely be based on that of a similar company like Netflix and could rise or fall in that time.

Hulu had 28 million subscribers at the end of April, a 12 percent jump since the end of last year. Although it is expected to lose more than $1.5 billion in 2019, Robert A. Iger, Disney’s chief executive, said he expected the service to reach 40 million subscribers and turn a profit by around 2024.