Fomer Barcelona's coach Josep Guardiola (Photo: AP)
Spaniard Guardiola, 41, will take over from Heynckes, who has decided not to extend his contract, in July and has agreed a deal until the end of June 2016, Bayern said in a statement on their website (www.fcbayern.telekom.de).
"We are very pleased that we have managed to convince the football expert Pep Guardiola, who was coveted and contacted by many top clubs, to come to Bayern Munich," Bayern CEO Karl-Heinz Rummenigge said.
"Pep Guardiola is one of the world's most successful coaches and we are sure that he can bring a great deal of sparkle not only to Bayern Munich but to German football in general," he added.
Bayern's announcement brings to an end weeks of speculation about which club would win the race to hire Guardiola, who announced this month he would return to coaching next season after taking a year out to rest.
He stepped down as Barca coach at the end of last term after leading the La Liga club, where he began his career as a player, to 14 trophies in four years, including two Champions League crowns and three straight Spanish league titles.
It is a significant coup for the German club, runners-up in the Champions League last season, given that big-spending rivals, including Chelsea, Manchester City and Paris St Germain, were reportedly also hoping to hire Guardiola.
The Spaniard, speaking to the English Football Association as part of the organisation's 150th anniversaray celebrations this week, had said his ambition was to manage in the Premier League in future.
Bayern are top of the Bundesliga with a nine-point lead after 17 matches. The league resumes this week after a month-long winter break.
(For more sports news and updates, follow Ahram Online Sports on Twitter at @AO Sports and on Facebook at AhramOnlineSports)