The 58-year-old succeeds Antonio Conte, who left the Serie A club at the end of May after two seasons in charge.
Conte guided Napoli to the 2024-25 Serie A title before the club finished second last season, a slip that ultimately cost him his position.
Allegri returns to Napoli having previously worn the club's shirt as a player during a brief spell in the 1997-98 season.
He arrives on a free after being sacked by AC Milan at the end of last season, and Napoli had been waiting for the termination of his Milan contract before completing the move.
Milan's decision to part with Allegri followed the club missing out on Champions League qualification, finishing fifth after winning only two of their final eight league matches.
His exit formed part of a wider restructuring at the San Siro club, with sporting director Igli Tare, technical director Geoffrey Moncada and chief executive Giorgio Furlani also leaving their positions.
Allegri is regarded as one of Italian football's most decorated coaches.
He won the Serie A title with Milan in 2011 before enjoying a hugely successful first spell at Juventus.
Between 2014 and 2019, he led the Turin club to five consecutive Serie A titles, four successive Coppa Italia triumphs and two Italian Super Cups.
Juventus also reached the Champions League final twice under Allegri during that spell, in 2015 and 2017.
He returned to Juventus in 2021 and lifted a fifth Coppa Italia in 2024, before taking charge of Milan for a second spell during the 2025-26 campaign.
Across his managerial career, Allegri has won six Serie A titles, five Coppa Italia trophies and three Italian Super Cups.
He has twice been named Serie A Coach of the Year, a reflection of the consistency he has shown across two decades in Italian football management.
Napoli will now look to Allegri to rebuild after missing out on the title last season, more than 25 years after he first wore the club's shirt as a player.
He becomes the latest high-profile appointment in a Serie A managerial merry-go-round that has also seen Milan restructure their entire football operations department, with Tare, Moncada and Furlani all departing this summer.
