Allegri's previous deal was set to expire at the end of next season.
The ex-AC Milan boss arrived at Juve in 2014 to replace Antonio Conte and has since guided the Bianconeri to seven trophies, which includes three straight Serie A and Coppa Italia triumphs.
The Old Lady twice narrowly missed out on a treble under Allegri, losing in the Champions League finals to Real Madrid this past Saturday and Barcelona in 2015.