T-Mobile has signed a merger agreemengt Sprint that will value Sprint at about $26.5 billion, people familiar with the matter told CNBC, and will place T-Mobile's chief in the top job.

The all-stock deal will be announced on Sunday, said the people, who asked not to be named because the negotiations are private. The transaction values Sprint at 0.10256 per T-Mobile share, or $6.62 a share based on T-Mobile's Friday closing price of $64.52, said the people.

The combined company with T-Mobile will have an enterprise value of about $140 billion. John Legere will run the company, which will have dual headquarters in Bellevue, Washington and Kansas City, according to one of the people. Some Sprint executives are expected to remain with the company even after a deal is announced, the person said.

SoftBank, which owns about 85 percent of Sprint, will allow Deutsche Telekom, which owns almost two-thirds of T-Mobile, to consolidate the new company's earnings, said the people. There is no breakup fee associated with the deal, they said. However, there is a roaming agreement that will kick into effect between the companies if a deal is rejected. Sprint customers would be allowed to use T-Mobile's network if they're out of range, two of the people said.

The new company will be about two-thirds owned by T-Mobile shareholders and one-third Sprint, with board representation in line with economic ownership, one of the people said.

The deal concludes several years of negotiations between the companies. Talks most recently broke off late last year after SoftBank CEO Masayoshi Son decided he didn't want to lose control of a combined company. Deutsche Telekom will own more than 40 percent of the new company, with SoftBank's ownership just below 30 percent.

Several things changed over the last few months that led Son to change his mind, including greater synergies from lower corporate taxes, an increased understanding of how much 5G deployment will cost Sprint, and a rapidly changing competitive wireless landscape that now includes cable providers, the people said.

Last week, Comcast and Charter, the two largest U.S. cable companies, announced an extended partnership agreement that will allow each company to develop products and services.

Another major factor was a shared fear among Sprint and T-Mobile that Verizon and AT&T will deploy 5G technology in select markets as soon as later this year, two of the people said. This expedited deal talks, as both companies initially believed they would have more time before 5G rolls out.

Still, the most important change may have been the settling of Sprint and T-Mobile share prices after months of deal speculation last year inflated both stocks, two of the people said. The $6.62-per-share price for Sprint is lower than what Sprint nearly accepted last year, one of the people said.

A deal announcement doesn't mean a merger will actually happen. Combining the third- and fourth-largest wireless U.S. providers in a market with only four participants — Verizon, AT&T, T-Mobile and Sprint — could be a hard sell for U.S. regulators. AT&T attempted to buy T-Mobile in 2011, only to have regulators block it on anti-competitive grounds.

Disclosure: Comcast is the owner of NBCUniversal, the parent of CNBC.