Allegri helped Juve win the Serie A and Coppa Italia titles this season, and guided them to the Champions League final. Since taking over at Juventus Stadium in 2014, he has won the domestic double each season and has a 69 per cent winning rate.
The former midfielder had been linked with a move to Arsenal before Arsene Wenger agreed a new two-year deal, but will now remain in Turin until the end of the 2019-20 season.
In a statement, Juventus said: "Juventus is pleased to announce that Massimiliano Allegri has signed a contract renewal at the club until 2020.
"Today's agreement extends a working relationship that has seen the Bianconeri consolidate their position as Italy's top team and also evolve into one of European football's major forces.
"Despite defeat in last weekend’s Champions League final in Cardiff, Allegri has undeniably transformed the club into a significant player on the continent. Two UCL finals in three years and fifth place in the UEFA ranking are clear testament to this."
In 2015, Allegri helped Juventus return to a first Champions League final in 12 years, and then returned to the same stage this year before being defeated by a Cristiano Ronaldo-inspired Real Madrid.
Allegri will receive a salary of €7 million per season under the new contract, which was agreed following discussions with club president Andrea Agnelli and CEO Beppe Marotta.
Allegri's first task after the renewal will be strengthening the squad to challenge for the Champions League next season, with a wide attacker and central midfielder high on the list.
Juventus have been linked with moves for Bayern Munich's Douglas Costa, PSG's Angel Di Maria and Federico Bernardeschi of Fiorentina. Liverpool's Emre Can, Lyon's Corentin Tolisso and Sevilla's Steven N'Zonzi have also been targeted to fill the central midfield position.