Rafael Benitez's side were consigned to a place in the UEFA Europa League in midweek despite beating Arsenal 2-0, but they showed an excellent response to that heartbreak.
All five goals came in a frantic first half in former Napoli coach Mazzarri's first return to the Stadio San Paolo since he departed for Inter in May.
Gonzalo Higuain opened the scoring with his 12th goal of the season, but Esteban Cambiasso levelled before Dries Mertens and Blerim Dzemaili struck in the space of two minutes to stun Inter.
Yuto Nagatomo pulled a goal back just before half-time, but Ricky Alvarez was sent off for a second bookable offence as Mazzarri’s side suffered their first defeat in 10 games,
The win was wrapped up by Jose Callejon’s late effort, while Samir Handanovic magnificently saved former Inter striker Goran Pandev's penalty in the game's dying embers.
Victory for Napoli moved them just two points behind second-placed Roma, who play Milan on Monday, and gave Benitez a win against one of his former employers.
The Spaniard made three changes to the side that beat Arsenal as Anthony Reveillere, Gokhan Inler and Lorenzo Insigne came in, while Mazzarri also made three alterations.
Rodrigo Palacio squandered a golden opportunity to put Inter in front after five minutes when he inexplicably headed over the bar from close range.
And he was made to pay for that miss four minutes later, when Nagatomo's poor defensive header looped up nicely for Higuain and the Argentina striker let fly with a left-footed volley.
Insigne rattled the post with a well-struck drive when he was set up by Mertens after 26 minutes.
But it came as no surprise when Inter drew level after 34 minutes with a well-worked goal. Fredy Guarin put in a cross from the right which was dummied by Palacio and helped on by Alvarez for Cambiasso, who finished clinically with his left foot.
Napoli then hit back with two goals in as many minutes. First Mertens raced forward to smash home a loose ball after Dzemaili had surged through the midfield 39 minutes in.
And Switzerland international Dzemail chipped in with a goal of his own from close range two minutes later after Samir Handovic could only push Mertens' shot into his path.
Inter refused to lie down and they were given a lifeline in first-half stoppage time as Guarin fired across the face of goal and Nagatomo was on hand to provide a simple finish.
Callejon fired just wide and Rafael denied Guarin from close-range as Napoli turned the screw after the break.
Inter's hopes of salvaging anything point looked remote when Alvarez was shown a second yellow card for handball with 19 minutes remaining.
And Napoli sealed the points nine minutes from time when Callejon turned home from close range, although Handanovic gave Inter fans rare cause to celebrate with a great save from Pandev's penalty in stoppage-time.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.