Giacomo Bonaventura and Davide Calabria had earlier given Milan the lead in their opening match of the campaign, but Piotr Zielinski's brace in the space of 15 second-half minutes hauled Napoli back on level terms.
The Naples outfit now sit joint-top of the early Serie A table alongside champions Juventus, having both maintained their perfect starts on Saturday.
The match saw a couple of high-profile faces take on former clubs, with Ancelotti's first home game in charge of Napoli coming against the club he served with such distinction as both a player and a manager, although there was not as warm a reception for Gonzalo Higuain as he returned to Naples in the red and black of Milan.
It was the visitors who drew the first blood, though, taking the lead after only 15 minutes when Fabio Borini's cross found Bonaventura, who fired a fine volley past debutant goalkeeper David Ospina from the edge of the box.
Napoli pushed Juventus all the way in the title race last season and will be hopeful of going one better this time around, but it took until the 39th minute for them to really threaten a response when Jose Callejon's powerful first-time drive zipped inches past the post.
Arkadiusz Milik also came close to levelling things up before the interval when he collected the ball on the edge of the box before going for goal, but Gianluigi Donnarumma was equal to the shot to ensure that the visitors kept their lead intact going into the break.
Things got even better for Gennaro Gattuso's side just four minutes after the restart when they doubled their lead through Calabria, who was found by Suso before firing his finish into the bottom corner.
The two-goal cushion lasted just five minutes as Napoli responded quickly this time, with Zielinski rifling an effort into the bottom corner from the edge of the box after being picked out by Callejon.
Zielinski continued to look the most likely to lead a comeback and he came close again shortly after the hour mark with a volley which had Donnarumma scrambling on its way wide of the target.
That proved to be a sighter for the pick of the bunch just four minutes later, though, as Zielinski almost single-handedly dragged his side back into the match with a brilliant long-range volley which flew into the bottom corner to level things up.
It was Zielinski's first brace of his professional career, but he could not turn it into a hat-trick and instead it was Mertens who completed the dramatic turnaround, tucking his finish home from close range after good work by Allan.
It could have got even better for the hosts too when Lorenzo Insigne forced a flying save from Donnarumma in stoppage time, but Napoli settled for the one-goal victory to make it two comeback wins from two in the new Serie A season.
NAPOLI (4-3-3): Ospina; Hysaj, Albiol, Koulibaly, Rui (Luperto 73'); Allan, Hamsik (Mertens 63'), Zielinski (Diawara 72'); Callejon, Milik, Insigne
AC MILAN (4-3-3): Donnarumma; Calabria, Musacchio, Romagnoli, Rodriguez; Kessie, Biglia (Bakayoko 58'), Bonaventura (Cutrone 81'); Suso, Higuain, Borini (Laxalt 71')body check tags ::