The 26-year-old wideman spent two seasons at the Allianz Arena after moving from Shakhtar Donetsk.
But after an uneven campaign in 2016-17 he has now been released on an initial one-year loan to the Serie A champions.
Juve will pay €6 million for the star at first, while the deal also includes a purchase option valued at €40m after the year is up. The option to buy becomes mandatory after Costa reaches a set number of appearances, though that figure is currently unknown.
Bayern could also receive an additional €1m should certain unspecified conditions be met.
Bayern CEO Karl Heinz Rummenigge expressed the club's satisfaction over the terms agreed with Juventus, while stating his gratitude for Costa's commitment to Die Roten.
"We have held some serious and constructive talks with the Juventus representatives," he said.
"All the financial demands of FC Bayern have been fulfilled. I want to thank Douglas for his performances.
"After two successful seasons with four titles he wanted to accept a new challenge. We accepted this and wish him, together with his family, all the best in Italy."
Costa follows Rodrigo Bentancur in signing for Juve in the transfer window, while Medhi Benatia and Juan Cuadrado have agreed permanent moves to the club following loans last season.
The winger made 34 appearances in all competitions last season under Carlo Ancelotti, despite admitting in February that he was unsettled in Munich.
He won two Bundesliga titles, the DFB-Pokal and the DFL-Supercup following a move from Shakhtar Donetsk in 2015 for a reported fee of €30m.