The 55-year-old has been in charge of the German champions on an interim basis since November last year, when he stepped up from his role as assistant manager to replace the sacked Niko Kovac.
Flick has impressed during his time in the Allianz Arena dugout, winning 18 of his 21 games in all competitions.
"FC Bayern and Hansi Flick are extending their cooperation. As a result of positive talks in a spirit of good faith, chairman Karl-Heinz Rummenigge, board member Oliver Kahn and sporting director Hasan Salihamidzic have agreed a contract extension with the head coach until 30 June 2023," the club said in a statement.
Bayern have recovered from an unconvincing start to the season as they held a four-point advantage at the top of the Bundesliga table before the Coronavirus pandemic curtailed the campaign.
The Bavarians also hold a 3-0 advantage over Chelsea from their UEFA Champions League round of 16 1st leg clash at Stamford Bridge while they are in the semi-final of the DFB-Pokal, where they will meet Eintracht Frankfurt.
"The club is very happy with Hansi Flick's work," said Bayern chairman Rummenigge.
"The team has developed under his leadership and we're playing attractive football, which is reflected in the results."
"We are the only German club still involved in all three competitions, and I like the way that Hansi leads the team."
"His personal qualities and his empathy speak volumes for him. Bayern Munich trusts him and we are convinced that we will reach our future goals with him."