Bayern said the 22-year-old Goretzka signed a four-year deal from July 1 through June 2022.

Schalke, which Goretzka joined in 2013 from hometown club Bochum, said the player informed the club this week of his wish to join Bayern when his contract expired.

"We think we did everything in the last months to convince Leon to stay with us," Schalke sporting director Christian Heidel said. "In the end, it wasn't enough."

Schalke had long been engaged in trying to get Goretzka to extend his contract, but was aware of reported interest from Bayern, Real Madrid, Barcelona, Juventus and Liverpool.

"We're very happy that Leon Goretzka, a German international with big potential, has decided in favor of Bayern despite big-name international competitors. This way it's ensured that Leon Goretzka remains in the Bundesliga," Bayern chairman Karl-Heinz Rummenigge said.

Goretzka scored 19 goals and set up 13 more in 130 appearances for Schalke.

The club had previously expressed its displeasure with Bayern making public statements about its player after Goretzka was praised by sporting director Hasan Salihamidzic and coach Jupp Heynckes.

Heidel said "we don't need to hear every day from the Munich people how good our player is."