Berlin - Schalke 04 confirmed Friday that Germany midfielder Leon Goretzka will join Bayern Munich at the end of this season on a free transfer, with the Bundesliga leaders beating Liverpool to his signature.
"Leon Goretzka informed us at the start of the week that he wants to leave the club and will join FC Bayern," said Schalke sporting director Christian Heidel.
"We did everything to keep Leon at Schalke."
The 22-year-old completed a medical in Munich on Thursday and has signed a contract until June 30, 2022, Bayern later revealed on their website.
"We are very happy that Leon Goretzka has decided to join Bayern, despite considerable competition from abroad," said Bayern chairman Karl-Heinz Rummenigge.
"This ensures that Leon Goretzka remains in the Bundesliga."
Goretzka, 22, has scored six goals in 12 appearances for his country.
He made his breakthrough at the 2017 Confederations Cup, where he helped a Germany side missing their World Cup-winning stars beat Chile 1-0 in the final.
The right-footed Goretzka joined Schalke from VfL Bochum in 2013 and has scored 19 goals in 130 games for the Royal Blues.
He can play as a deep-lying midfielder, winger or attacking midfielder and his versatility will be a bonus for Bayern.