Costa, 27, moved to Juve in 2017 on loan after falling out with the Bayern board and then-coach Carlo Ancelotti over a reduction in playing time.
The Brazil international racked up 47 appearances in all competitions, helping the Old Lady to a seventh consecutive Serie A title and the Coppa Italia while also playing a key role in their trip to the Champions League semi-finals.
And that impressive debut season has been rewarded as the Italian giants chose to exercise the purchase option in the initial loan deal agreed with Die Roten.
"Juventus have exercised the option right for the permanent purchase of the player Douglas Costa from Bayern Munchen for a fee of €40m to be paid in two financial years," Juventus revealed on Thursday in a statement.
"The consideration may increase €1m upon the fulfilment of certain conditions over the course of the duration of his contract".
Costa is currently preparing with the Brazil national team ahead of this month's World Cup.