Heynckes, 72, will come out of retirement to take take charge of the squad from Monday, the fourth time he has coached Bayern.
"There is a strong relationship of trust between Jupp Heynckes and FC Bayern," said club chairman Karl-Heinz Rummenigge.
Heynckes will be assisted by the current co-trainer of Fortuna Duesseldorf, Peter Hermann and the current sports director of Bayern's youth team, Hermann Gerland.
It was along with Hermann and Gerland that Heynckes led Bayern to win the 2013 treble, the first -- and only time -- a German club won the Bundesliga, Champions League and German Cup titles in a season.
"I would not have returned to any other club in the world, but Bayern Munich is close to my heart," said Heynckes, vowing to transform the team back into a "successful" squad.
In an interview with Kicker magazine, Heynckes said he was "not making a comeback, it's a service for a friend."
"I'm doing it only because I owe a lot to Bayern."
The Bundesliga champions made no mention of former French international defender and Bayern stalwart Willy Sagnol, who had stepped in as interim coach after the shock departure of Ancelotti.
Bayern are languishing in third place in the Bundesliga, five points behind leaders Borussia Dortmund.
A stinging 3-0 defeat to Paris Saint-Germain in the Champions League led the club to sack Ancelotti last month.
Heynckes previously coached Bayern from 1987 to 1991, briefly in 2009 and then between 2011 and 2013.