The 22-year-old, whose contract with the Royal Blues is set to expire at the end of the current season, has signed a four-and-a-half-year deal with the reigning Bundesliga champions.
Watch: Goretzka joins Bayern Munich!
"We are very happy that Leon, a German international with great potential, has decided, despite considerable competition from abroad, to join Bayern Munich," said Bayern München CEO Karl-Heinz Rummenigge.
Goretzka rose through the ranks at VfL Bochum before joining Schalke at the age of 18 in summer 2013. He has scored 14 goals in 101 Bundesliga appearances for the club, and has since developed into one of the most high-rated young players in Europe, as well as becoming a full Germany international and helping Joachim Löw's side win the 2017 Confederations Cup in Russia.
"Leon told us at the start of the week that he wanted to leave the club, and move to Bayern Munich," Schalke sporting director Christian Heidel confirmed on Friday.
"He has signed a contract with Bayern and will join from 1 July, 2018. We've done everything we can to keep Leon at Schalke. In the summer there was an agreement with him and his advisor. He still wanted time to wait and develop himself."
Watch: Bayern boss Jupp Heynckes believes Goretzka's move is "positive for the Bundesliga and Bayern"