Hamsik lashed home a cross from Ezequiel Lavezzi in the 14th minute then three minutes later Cavani converted a penalty after Lavezzi was tripped by Gonzalo Rodriguez in the box.
It was a fine result for Napoli on the back of their opening draw against Manchester City at the Etihad Stadium, while the Spanish side remain bottom of the group with no points.
Walter Mazzarri's men had gone into the game on the back of a slight stutter in Serie A with a surprise 1-0 defeat at Chievo followed by a goalless draw at home to Fiorentina on Saturday.
Meanwhile Villarreal travelled to Italy on the back of a creditable weekend draw away to Athletic Bilbao in the Primera Liga and were confident of breaking their Group A duck.
A frenetic opening produced free-kick opportunities for both teams with Giuseppe Rossi firing into the Napoli wall and both Lavezzi and Andrea Dossena having chances for the home side.
The first chance from open play fell to Villarreal's Ruben Cani in the eighth minute, but the Spaniard's rising 20-yard shot cleared the bar above home keeper Morgan De Sanctis.
Lavezzi fired over the for the home side before Slovakian Hamsik gave the Italians the lead, sliding home a left-foot shot from the edge of the six-yard box after Lavezzi's cross from the right.
Cavani's penalty four minutes later left the home side well in control but Villarreal pressed in search of a goal to narrow the deficit and Brazilian Nilmar was close with a right-foot effort on the half-hour.
Rossi also came close to the visitors who pressed via a series of dangerous corners and continued to hunt for a goal early in the second half, with Jonathan De Guzman blazing a free-kick over the bar.
Rossi had a chance on 50 minutes when Javier Camunas crossed and found the striker's head on the edge of the six yard box, but De Sanctis matched Rossi's effort with a fine save from point-blank range.
Gokhan Inler saw an ambitious 30-yard effort drift wide of goal in the 65th minute before Rossi again came close for the visitors, this time seeing his shot blocked by Camilo Zuniga in the box.
Camunas shot over the bar and Rossi had an effort blocked by Cannavaro as Villarreal continued to enjoy the majority of the clear-cut chances without finding the goal required to get them back in the game.
The home side, more than happy to sit back and protect their two-goal cushion, allowed the game to descend into a series of set-pieces, all of which De Sanctis dealt with comfortably.