Nagelsmann, 35, had taken over in 2021 and led the Bavarians to their 10th straight German league crown, but failed to win another trophy last season.
Bayern were knocked out in the round of 16 of the German Cup by Borussia Moenchengladbach and knocked out of the Champions League in the quarterfinals by Villarreal last season.
However, his departure came as a big surprise as Bayern prepare to face leaders Borussia Dortmund next week in the Bundesliga and Manchester City in the Champions League quarter-final on April 11.
“We came to the conclusion that the quality of our squad was less and less visible despite winning the league last season,” Bayern general manager Oliver Kahn said.
“After the World Cup we were playing less successful and less attractive football, and the ups and downs of our level jeopardized our objectives for the season. That’s why we have reacted now.”
Nagelsmann’s successor Tuchel, who had long been a Bayern target since their first attempt to sign him in 2018, has signed a deal until 2025, the club said.
Tuchel won the Champions League with Chelsea in 2021 after replacing Frank Lampard, but has been out of a job since being sacked by the English team last year.
The 49-year-old also won back-to-back French league titles during his time at Paris Saint-Germain and led the French side to their first Champions League final in 2020, which they lost to Bayern.