Milan move back two points ahead of Sassuolo -- 2-0 winners earlier at Hellas Verona -- with Roma third after Henrikh Mkhitaryan scored twice in a dominant 3-0 win over Parma.
Ibrahimovic continued his fine form, heading in a Theo Hernandez cross after 20 minutes, sending in the second with his knee nine minutes after the break.
But the 39-year-old pulled up clutching his left hamstring and was substituted after 79 minutes.
The Swede has scored in all six games he has played this season, having missed two after contracting coronavirus.
Coach Stefano Pioli missed the trip south with Covid-19, but his side got their first league win in Naples since October 2010, the season they last won the Scudetto, with Ibrahimovic also on the scoresheet that time.
Napoli played the final half an hour a man down after Tiemoue Bakayoko was sent off for two yellow cards, just after Dries Mertens had pulled a goal back for the hosts.
Norwegian Jens Petter Hauge completed the scoring five minutes into injury time with the 21-year-old getting his first Serie A goal.