It meant that Carlo Ancelotti got the better of Milan counterpart Gennaro Gattuso, who used to play under the new Napoli coach when he was with the Rossoneri.
After Giacomo Bonaventura (15 minutes) and Davide Calabria (49) took advantage of questionable goalkeeping from David Ospina to give Milan a 2-0 lead.
Piotr Zielinski then scored twice before Mertens was left unmarked to tap the ball in 10 minutes from time.
Milan, meanwhile, remain without a point and are off the foot of the table only on goal difference.
Afterwards Carlo Ancelotti spoke about a “special” relationship with Gennaro Gattuso and explained his tactical changes that led Napoli to victory.
It was his first match against beloved Milan in 17 years and he was taking on former player Gattuso, but the Master came out on top with a 3-2 victory after trailing 2-0.
“Milan played a splendid game, but after going 2-0 down, we showed great desire not to let go, to keep believing in our chances and to fight back vehemently,” Ancelotti told DAZN.
“I have a fond memory of all my former players, but with Gattuso there is something special. It’s a wonderful evening, one full of emotions for me. We’ve all been fortunate to experience it and I didn’t even have to pay for a ticket!
“Milan hadn’t really given many signs of being dangerous in attack, but surprised us with two similar goals. It was very difficult in that situation, then we changed system and the crowd pushed us on to turn it around.
“This team knows the 4-3-3 very well, but can also play 4-2-3-1. We weren’t putting enough pressure on Lucas Biglia and I had to change something in midfield.”
Dries Mertens came off the bench and scored the winner, showing he can play with Lorenzo Insigne, Jose Callejon and Arkadiusz Milik.
“He is certainly not a typical trequartista, but Mertens is very good when combining with both Insigne and Milik. He doesn’t play behind the striker as such, but slightly wider to the left, so that pushes Insigne further out to the left and we make more of the wings.
“I think Marek Hamsik is doing very well as a playmaker. He’ll improve once we get a little more organised and he’ll have the opportunity to use his long balls.”