Alberto Aquilani put the visitors ahead in the 11th minute before Cavani equalised shortly after.
Cavani struck his second in the 36th minute and the Uruguay forward completed his hat-trick six minutes after half-time as his team secured the win.
Ezequiel Lavezzi recovered from a muscular injury and played from the start alongside Cavani and Marek Hamsik in Napoli's attack.
Milan, who were without several players including injured striker Zlatan Ibrahimovic, could not have asked for a better start.
The defending champions took an early lead when Aquilani got his head on Antonio Cassano's cross and beat Napoli goalkeeper Morgan De Sanctis.
Milan's joy was shortlived as Napoli equalised two minutes later.
Christian Maggio headed a free-kick straight into the path of Cavani, who slotted the ball past AC Milan goalkeeper Christian Abbiati.
In the 25th minute, Gokhan Inler's 30-yard free-kick was off target.
Napoli pressed forward and were rewarded in the 36th minute.
Walter Gargano was allowed to run half the length of the field and into the box before serving Cavani inside the area and his diagonal right-footed strike beat Abbiati.
Milan twice had the opportunity to pull level before the break.
Cassano fed Aquilani inside the area and his 10-yard effort towards the far post was met by an excellent save from De Sanctis.
Shortly after, Aquilani's right-footed strike from outside the area went inches wide of the far post.
Napoli made it 3-1 early in the second half.
Milan's defence failed to clear the ball inside the area leaving Cavani to fire past Abbiati.
On the hour mark, Alexandre Pato's bullet strike from 30 yards was saved by De Sanctis.
Milan continued to press forward and could have reduced the deficit in the 70th minute, Pato's powerful header from Cassano's cross going over the bar.
Cavani almost scored his fourth of the night with five minutes remaining but his right-footed strike was kept out by Abbiati.
Napoli's convincing win will fill them with confidence as they look to challenge for honours in Italy and Europe this season.