Ancelotti, 58, replaces Maurizio Sarri, 59, who has been linked with a move to replace Antonio Conte at the Premier League club, Chelsea.
“I am really happy and honoured to manage a team with a unique city and incredible fans,” said Ancelotti.
Earlier on Wednesday, Napoli president Aurelio de Laurentiis praised Sarri for his contribution to the club.
De Laurentiis said: “I thank Maurizio Sarri for his dedication to Napoli that has given the city and the fans worldwide prestige and emotions.
“He created a model of play admired everywhere and by anyone. Bravo Maurizio.”
Ancelotti has won four top-tier league titles, three Champions Leagues and three domestic cups across Europe’s top five leagues.