Pirlo, 42, replaced Maurizio Sarri last summer but could only steer Juventus to fourth place in Serie A, as their nine-year hold on the Italian title finally came to an end.
Allegri was Juve manager from 2014 to 2019 and won the league title in each of those five campaigns as well as the Coppa Italia on four occasions.
Under Allegri, Juve also reached the Champions League final twice. Prior to joining Juve, Allegri had led AC Milan to their last Serie A title in 2010-11.
Bentornato, Max! ⚪⚫#AllegriIN
— JuventusFC (@juventusfc) May 28, 2021
A club statement read: “Thanks Andrea. These are the first words that all of us must pronounce at the end of this special experience lived together.
“For the courage, the dedication, the passion with which he demonstrated every day, our thanks go to the ‘Maestro’, the coach and to Andrea, that really comes from the heart, as well as our good luck for the future that will surely be a wonderful one.
“Massimiliano Allegri is the Juventus manager once more. Allegri finds a bench that he knows very well, a club that he loves and that loves him back, as today a new journey begins together, towards new goals.
“What he achieved in his first adventure at Juventus are engraved in the club’s history: five Scudetti, to the four-consecutive doubles, coupled with the Coppa Italia and to the two Super Cups, reaching two Champions League finals in just three seasons, in what were epic feats both in Italy and in Europe.”
View this post on Instagram
Pirlo thanked Juve with a lengthy posted on Instagram which read: “If I had to go back I would make the exact same choice again, although aware of all the obstacles I encountered in such a difficult time for everyone, which prevented me from better planning my intentions and my style of play.
“This adventure, despite an unexpected ending, made it even clearer what I would like my future to be, which I hope will be just as complete and fulfilling as the one I experienced as a player.”
“It’s been an intense, complicated year but still wonderful. When I got the call from Juventus, I never thought about the risk I was taking.”