Midfielder Eljif Elmas glanced a header home at the near post from a corner to stun the hosts and edge the visitors in front in the fifth minute, a lead Napoli held without being overly troubled until the latter stages.
Veteran Milan striker Zlatan Ibrahimovic looked most likely to find an equaliser after going close midway through the first half and just after the break.
In the 90th minute, as Milan looked out of ideas, Franck Kessie appeared to have snatched a point, sparking wild scenes of celebration, only for VAR to rule it out for offside against Olivier Giroud as he lay on the ground in the penalty area.
Milan were furious with the call but Napoli held on for a first win in four league games to reach 39 points, the same as Milan but above Stefano Pioli's team on goal difference.
"What really made me happy was we didn't get too deep until the final five minutes, we kept the balance right even after taking the lead," Napoli coach Luciano Spalletti told DAZN.
"It became difficult in the final minutes when Olivier Giroud added his presence to the physicality of Zlatan Ibrahimovic. But we had chances to go 2-0 up and we played like a great team against a great opponent."
Milan and Napoli went unbeaten in their opening 12 league games of the season, but the pair's indifferent form since has opened the door for Inter Milan, who are now assured to be 'winter champions' in Italy as they are top by four points with one round of matches to come before the Christmas break.
Having been top of the standings for so long, Napoli knew a fourth defeat in six league games would leave them with it all to do to catch Inter, but they gave themselves the perfect platform with Elmas' early opener.
Both teams were missing several key players through injury and it showed in an ugly affair low on quality.
All the drama took place right at the death. Kessie's effort was scrappy but Milan did not care one bit, with Pioli even running over to join in the celebrations.
Referee Davide Massa was asked by the VAR to have another look at the goal on the pitchside monitor, and ruled that substitute Giroud, who was prone on the turf, was offside when attempting to get involved in the build-up.
"I know they will say the rules were applied, but how can a player who is lying on the floor possibly damage the opponent?" Pioli told DAZN.
"There is no way he is obstructing [defender] Juan Jesus. Giroud's legs are wide, he is trying everything to get out of the way."