“We are very happy to have agreed a two-year contract," club president Karl-Heinz Rummenigge said. "I am convinced that our cooperation with Jupp Heynckes will be successful."
Heynckes, 65, won two league titles with Bayern between 1987 and 1991, then took over again for five games at the end of the 2009 season. He also won the Champions League with Real Madrid in 1998.
Heynckes, who is leaving Bayer Leverkusen at the end of the season, said he was looking forward to his comeback.
"Quite apart from my good personal relations with bosses at Bayern I have always been very impressed with how professionally the club is run," the silver-haired German said.
With the speed that Bayern have gone through coaches in recent years, Heynckes said he knew what he was getting himself into, saying that he was relishing the chance to bring the club back to winning ways.
"Of course as Bayern Munich coach success is a bit of a must. I see the coming two seasons with the players as an exciting challenge," he said.
Van Gaal is leaving under a cloud, with his team fourth in the table, 14 points behind runaway leaders Dortmund, a poor season by Bayern standards.
They were also knocked out of the Champions League by Inter Milan at the last-16 stage. Last season they won the league and cup double and were Champions League finalists.