The Azzurri had failed to win in five games and risked surrendering second spot to AC Milan, who beat Palermo 2-0 today, but Cavani ended his own six-week goal drought with an early penalty to hand his side the initiative.
Paolo Cannavaro's own-goal did not help Napoli's cause, though, and Cavani was relieved to have doubled up just before German Denis levelled the tie once again midway through the second half.
Goran Pandev then pounced in the final 10 minutes to keep the southerners within nine points of leaders Juventus and two points clear of third-placed Milan.
Napoli's recent malaise had coincided with Cavani's dry spell in front of goal, and so it appeared the fog had finally lifted when the Uruguayan opened the scoring.
Juan Camilo Zuniga tumbled in the area under the attentions of Luigi Giorgi in the fourth minute and Cavani duly converted his first goal in seven league games from the spot.
Pandev came desperately close to adding a second in the 16th minute, but the Macedonian put his shot wide of the post following a swift exchange of passes with Marek Hamsik.
Cavani missed another fine chance moments later, again from a Hamsik pass, and Atalanta soon grew into the game before levelling in the 31st minute.
Denis' cross from the right found Giacomo Bonaventura sliding underneath the ball, but, luckily for the visitors, Cannavaro was there to put through his own net.
Atalanta almost completed an unlikely turn-around before the break, but Carlos Carmona's fierce free-kick was kept out by the crossbar.
For a while it seemed Napoli's frustration would carry through to the second half as Andrea Consigli made fine stops on Blerim Dzemaili and Cavani, with the latter spooning another Hamsik cross over the bar in between times.
But the 65th minute brought a second Azzurri goal as Cavani twisted his body in the box to drive home an angled drive at the San Paolo.
Napoli's joy was shortlived, however, as Denis skipped through the offside trap eight minutes later. The Argentinian then judged Morgan De Sanctis' dash off his line perfectly to find the back of the net with a shot to the far post.
This was a red rag to a bull as far as a reinvigorated Napoli side were concerned and Pandev soon found a way to beat Atalanta's defences for the third time.
There were nine minutes left to play when substitute Pablo Armero stormed down the left wing to pick out Pandev, who gave Consigli no chance with a sumptuous left-footed volley.
Napoli coach Walter Mazzarri was then sent to the stands for protesting an official's call, but his final act of replacing Pandev with defender Rolando proved enough to shore up the final minutes and guarantee an invaluable victory.