Bayern Munich has hired Leipzig coach Julian Nagelsmann to replace the departing Hansi Flick.
Nagelsmann, 33, will move to Bayern on July 1 with a contract that runs until 2026.
Bayern said it agreed to terminate Flick's contract after he asked to be released early.
Leipzig CEO Oliver Mintzlaff said Bayern agreed to its demand for a high fee for Nagelsmann, without specifying a sum.
Nagelsmann grew up near Munich and came through the youth system at another club in the city.
"There were some inquiries from other clubs. I told Oli (Mintzlaff) that I wouldn't want to end my contract for any other club but this one," Nagelsmann said.
He added the first contact from Bayern came on April 16 after Leipzig's game against Hoffenheim. That was after Flick told Bayern management he wanted to leave but a day before he went public.
Nagelsmann has been with Leipzig for three years and led the team to the Champions League semi-finals in 2020. Leipzig is in second place behind Bayern in the Bundesliga and will play Werder Bremen on Friday for a place in the final of the German Cup.
Nagelsmann was the youngest head coach in league history when he took over at Hoffenheim at 28 in 2016. The team then qualified for the Champions League for the first time in its history.
Nagelsmann was a professional player but moved into coaching when his career ended early because of knee injuries.
"Julian Nagelsmann signifies a new generation of coaches," Bayern president Herbert Hainer said. "Despite his young years, he has already built an impressive career. We are convinced that we will build on the great successes of recent years together with Julian Nagelsmann."
Nagelsmann will join up again with defender Dayot Upamecano, who is also moving to Bayern from Leipzig at the end of the season.
Bayern was forced to look for a new coach after Flick said this month he wanted to leave the club despite having a contract through 2023. Flick won the league, German Cup and Champions League last season with Bayern and is on the verge of bowing out with another league title.
Bayern will secure the Bundesliga title if it wins its next game on May 8 against Borussia Mönchengladbach or if Leipzig loses to Borussia Dortmund the same day.
Bayern initially appointed Flick in 2019 as an interim coach when Niko Kovac was fired. He was supposed to step in for a few weeks but the team's winning run meant he was given an extension, first until the end of the 2019-20 season, then until 2023.
Flick has not been able to celebrate any trophies in front of the team's fans because of the pandemic. Only the European Super Cup in Hungary and Club World Cup in Qatar were won in front of small numbers of supporters.
In a statement from Bayern Flick said: "One tinge of sadness remains, that we could not celebrate the great successes during this period with the fans. I've missed you in every match."
56-year-old Flick has been linked with the Germany job, which will be vacant once Joachim Löw steps down after the upcoming European Championship. Flick was Löw's assistant from 2006 until Germany won the World Cup in 2014.
Leipzig CEO Mintzlaff said losing Nagelsmann to Bayern didn't mean the Red Bull-funded club was lowering its ambitions. He said the club plans to strengthen the squad and wants a successor who will "continue with what Julian has built."
Mintzlaff denied reports an agreement had been reached with Salzburg's Jesse Marsch and said there was a shortlist of three coaches.
"Next season we're going to go full-on attack, and that means attacking Julian Nagelsmann and FCB," Mintzlaff said.