Napoli's attacking trio of Marek Hamsik, Ezequiel Lavezzi and Cavani looked dangerous every time they went forward, slicing holes in the City defence.
On paper, it had looked a mismatch between the unbeaten Premier League leaders and a side who are a modest seventh in Serie A.
City have spent five or six times more on their team than the Serie A club, according to Napoli president Aurelio Di Laurentiis.
"At the start I was worried," said Napoli coach Walter Mazzarri. "They looked strong, confident, I didn't think we would win, I thought it was a risky match, but the more the match was progressing, the team grew in confidence and the more I felt we could do it."
City began confidently but Napoli looked dangerous with every attack. Hamsik headed straight at Joe Hart from Lavezzi's cross, then Lavezzi himself fired wide after a one-two with Cavani.
Benfica advance as sloppy United fretThe Uruguayan, struggling to repeat last season's prolific scoring this term, gave Napoli the lead in the 18th minute when he flicked on a corner and the ball deflected off two City players into the net.
Almost immediately, Cavani struck the side-netting following another quick break but the Napoli storm then blew itself out and City levelled in the 33rd minute.
Edin Dzeko crossed, Salvatore Aronica sent a dreadful clearance straight to David Silva in the penalty area and, although his angled shot was saved by Morgan De Sanctis, Balotelli was on hand to snap up the rebound.
City appeared to be on top but it was Napoli who regained the lead four minutes after the restart.
Lavezzi worked an opening for Andrea Dossena on the left and he pulled the ball back into the middle for Cavani to side-foot home.
The Italian side fell back into defence and frustrated City but were always dangerous on the break. Lavezzi forced a superb save from Hart after slipping his marker, then Hamsik hit the post.
Napoli were forced to defend desperately in a gripping final 15 minutes. De Sanctis saved a clever Balotelli volley and stopped another awkward shot from the Italian following a corner.
"Our target was to go into the second stage, we depend on the other team but in football everything can happen," Mancini said.
"It's important we win our game against Bayern Munich and our life doesn't finish if we don't go through."