The former Barcelona boss, who had been linked to Chelsea and Manchester United, will take over at the Allianz Arena in the summer, ending months of speculation over his future
The 41-year-old former Barcelona boss, who has signed a deal with the Bavarian club until 2016, has been on a sabbatical from the game since leaving Camp Nou in 2012, having won 14 trophies with the Liga side during his four seasons in charge.
Heynckes, who has been boss at Bayern since 2011, told die Roten officials before Christmas that he would not be continuing in his role beyond the current season, leaving the German side to attempt to secure Guardiola's services.
And the Spaniard, who had been linked with a host of top-flight clubs across Europe, including Manchester City and Chelsea, has now signed a three-year deal with the German side.
"We are very happy that we managed to land Pep Guardiola for our club. He was contacted by lots of big teams," Bayern CEO Karl-Heinz Rummenigge said in a statement.
"Pep is one of the most successful coaches in the world and we are convinced that he will not only shine for Bayern, but for the whole of German football. We look forward to beginning our work from July 2013.“
And Rummenigge praised outgoing Bayern boss Heynckes, adding that securing the Bundesliga crown would be a fitting send off for the German.
"As a club and as Jupp Heynckes' friends, we have to show understanding for this decision. We have to accept it and we have to respect it," he said.
"During personal talks with Jupp Heynckes we assured each other that we will do anything we can, and now even more, to have a successful second half of the season , in which we want to get the title to Munich.“
Bayern currently lie top of Germany's top flight, nine points clear of second-placed Bayer Leverkusen.