Cavani scored the opener from the spot after Napoli were awarded a harsh penalty – with the ball striking Milan Milanovic on the arm after it deflected off his thigh.
Napoli doubled their lead before the break through the outstanding Hamsik, who slotted under Emiliano Viviano after Goran Pandev’s hooked through ball.
Napoli went into this game as one of four teams all chasing that coveted third Champions League place.
The Partenopei were tied on 55 points in the race for third, but this result puts Walter Mazzarri’s side in pole position to compete in Europe’s premier competition for the second successive year.
Palermo, who were without their influential captain Fabrizio Miccoli, still need a win to secure their Serie A survival.
Napoli could have led inside five minutes when Gokhan Inler hit the bar, but moments later Palermo were thwarted by a double save by Morgan De Sanctis.
The visitors cut Napoli open as Nicolas Bertolo cut the ball back to Josip Ilicic, who could only find the keeper when he should have scored. De Sanctis picked himself up to make a save from Abel Hernandez.
Chances continued to fall for both sides, but the pendulum swung Napoli’s way after they were awarded a controversial penalty when Pandev’s cross from the left struck the thigh of Milanovic and then onto his hand.
Despite the vehement protests, Cavani dispatched his powerful penalty hard into the bottom corner.
Palermo’s early enthusiasm receded after going behind and Napoli started to dominate, with Juan Camilo Zuniga going close at the far post after Cavani flashed a volley across the face of goal.
But Napoli put daylight between them and Palermo when Hamsik’s intelligent run was picked out by Pandev, who hooked a ball over the Palermo defence, and the Slovakian slotted the ball under the advancing Viviano.
Palermo were dealt a blow early in the second half when injured striker Ilicic had to be replaced, and Napoli almost put the game beyond them moments later – but Cavani spurned a good chance, dragging his shot wide under pressure from Ezequiel Munoz.
While the first half was open and attacking, the second was a cagey affair and substitute Eran Zahavi went close with two long-range efforts.
Palermo put the ball in the net – but it was controversially chalked off for offside after Hernandez had struck the ball into the roof of the net.
But that was as close as Palermo got as Napoli saw out the game to earn a rare clean sheet and move three points clear of their rivals in a race for third that remains wide open.