Legere will stay on as chief executive through the end of his contract, which expires April 30, 2020. He will remain a member of the board, the company said.
T-Mobile is the third-largest wireless carrier in the U.S.
"John Legere has had an enormously successful run as CEO," Tim Höttges, Deutsche Telekom CEO, and chairman of T-Mobile US' board of directors. "As the architect of the Un-carrier strategy and the company's complete transformation, John has put T-Mobile US in an incredibly strong position."
Legere, who has run the company for six years, tweeted that the move "has been under development for a long time."
"You've heard me joke that he's 'my son,' but in reality, since I hired him in 2012, @SievertMike's been my mentee, my secret weapon and my friend," Legere said.
Embattled shared-workspace firm WeWork has reached out to Legere to help fill the C-suite as soon as January, FOX Business' Charlie Gasparino reported last week. It is unclear how serious discussions have been.
If interested, Legere would take over for WeWork co-founder Adam Neumann, who was forced out as CEO amid a failed initial public offering.
The departure announcement comes after the Federal Communications Commission approved a $26.5 billion merger between T-Mobile and Sprint.
The two companies promised the government they would build a 5G network that would cover 97 percent of Americans in the three years after the finalized deal.