The Germany international, who joined Bayern in 2018, has decided to see out the campaign in Munich despite interest from several European clubs, including Atletico Madrid, during the January transfer window. The 30-year-old midfielder remained focused on helping Bayern chase another Bundesliga crown before moving on as a free agent.
Sporting director Christoph Freund praised Goretzka's commitment and professionalism.
"Leon feels very much at home in this club and this team," Freund said. "Despite several quality inquiries, he has decided to stay here until the end of the season. After open and constructive talks, we have come to the conclusion together that he will seek out a new challenge in the summer."
He added: "It'll be eight years at Bayern - eight extremely successful years with a strong person and player. Leon will give his all up to the summer to win as many more titles with the team as possible."
Goretzka, played nearly 300 matches for Bayern and remained part of Vincent Kompany's squad this season, making 28 appearances across all competitions so far.
During his time in Munich, he won six Bundesliga titles, two German Cups and three German Supercups, as well as the Champions League, UEFA Super Cup and FIFA Club World Cup in 2020.
Goretzka now aims to finish his Bayern career by helping the club secure what would be his seventh Bundesliga title before starting a new chapter elsewhere.