The highly-rated Uruguayan lifted the Italian side back into second in Group A with goals either side of a Mario Balotelli equaliser at the intimidating Stadio San Paolo.
City had several chances in an eventful game but Marek Hamsik also hit the post for the hosts, who dominated for long spells.
The Premier League leaders will now have to win their final game against group winners Bayern Munich and rely on a favour from winless Villarreal against Napoli to progress.
The night in Naples was another learning curve for a side who may be dominant domestically but are still off the pace at elite European level.
Cavani, Hamsik and Ezequiel Lavezzi - all of whom have been linked with City - were a handful all night in an imposing atmosphere.
The level of hostility facing City in the vast arena was apparent long before kick-off and there was little let-up in the noise throughout the game.
The huge crowd were not only boisterous but had a seemingly large supply of fireworks and ear-piercing whistles greeted every spell of City possession.
City supporters were greatly outnumbered but did their best to contribute to the atmosphere by setting off a number of firecrackers themselves.
A City side showing four changes from the weekend initially seemed as though they would not let it bother them as they looked to build attacks patiently.
City boss Roberto Mancini started with Edin Dzeko up front alongside Balotelli with Sergio Aguero on the bench.
As is customary, he rotated his full-backs, meaning there was no place for in-form Micah Richards on the right as Pablo Zabaleta came in.
Aleksandar Kolarov and David Silva were the other men to return and both were prominent as City probed.
Their first real opportunity saw Yaya Toure fire over before Balotelli bent a long-range effort wide.
Napoli hit back on the break and went close as Hamsik headed straight at Joe Hart from a Lavezzi cross.
Encouraged, Napoli then took charge with Lavezzi shooting wide after neat interplay with Cavani on the edge of the box.
Lavezzi got on the end of a cross from former Liverpool player Andrea Dossena but his volley was deflected wide.
Hart was then extended as Gokhan Inler forced Hart to palm over from long range but City were undone from the resulting 19th-minute corner.
Cavani met Lavezzi's set-piece with a glancing header and the ball found a way past Hart at his near post.
It took some time for City to regain a measure of possession after falling behind but one steady move ended with Silva screwing a shot well wide.
City pressed again and levelled after 32 minutes when a poor clearance from Paolo Cannavaro went straight to Silva, who fired straight at Morgan De Sanctis. The keeper parried but only as far as Balotelli, who gratefully tapped in from close range.
Kolarov broke into the area as City threatened a second just before the break but shot straight at De Sanctis.
What had been hard work to get back into the game was undone four minutes into the second half as Napoli regained the lead.
The visitors were caught out down their right as Dossena managed to get behind Zabaleta and pull back for Cavani in front of goal.
The Uruguayan made no mistake as he sidefooted home his second with precision, although Hart could arguably have done better.
City came under further siege as Joleon Lescott blocked a shot from Hamsik and the Slovakian headed the rebound over. Inler put another attempt wide.
Silva tried to stir a response but badly miscued another shot.
Kolarov teed up Balotelli at the end of a good move but the City striker could not make firm contact in front of goal.
Hart needed to be alert at the other end to cut out a cross from Christian Maggio and did even better to deny Lavezzi after he was played in by Cavani and skipped past Vincent Kompany.
City were fortunate not to concede a third when Hamsik weaved his way into the box and struck the base of the post with a powerful shot.
Maggio then went through on goal as City were exposed again but Hart came out to smother the ball.
Yet City were not downhearted and Balotelli headed another good chance over from a cross from substitute Samir Nasri.
Silva forced another save from De Sanctis as City pushed for a late equaliser but Napoli held on.