After helping the club win its first Serie A title in over a decade, the 51-year-old left the Italian giants in a shocking move.
The appointment comes one week after Napoli terminated the services of Genarro Gattuso after an underwhelming season.
Allegri was Juventus manager from 2014 to 2019 and won the league title in each of those five campaigns.
Pirlo replaced Maurizio Sarri last summer but could only steer Juventus to fourth place in Serie A.
Simone Inzaghi joined Lazio in 1999 as a player and won one Serie A and three Coppa Italia titles before retiring in 2010.
Gianluigi Donnarumma will leave AC Milan next month as his contract expires on June 30, the 22-year-old goalkeeper made 251 appearances for the Italian giants.
In a surprising move, Inter Milan coach Antonio Conte left the newly-crowned Serie A champion by "mutual consent" on Wednesday.
Gennaro Gattuso left Napoli after failing to secure a Champions League spot; Lanchini departed from Fiorentina after an underwhelming season.
AC Milan, Napoli and Juventus were involved in a three-way battle for the final two Champions League berths for Italian clubs.
Serie A champions Inter Milan ended their triumphant season with a 5-1 thrashing of Udinese on Sunday.