The win keeps Mazzarri's team just about still in the title race, nine points adrift of leaders Juventus, but perhaps more pressingly, two points clear of second-place AC Milan. Torino continue to drift aimlessly in mid-table, nine points clear of the relegation zone.
Napoli had the better of the match early on, controlling possession while Torino looked to play on the counter-attack through winger Alessio Cerci. The pressure told when Blerim Džemaili drilled a thunderbolt into the top corner first time from the edge of the box, giving the Neapolitans the lead against his former club.
Torino still posed a threat on the counter-attack, and Mario Santana should've also had a goal against his former club five minutes later, after he headed a cross by Barreto narrowly over the bar from close range.
It was a rare Torino chance, with Napoli pushing for a second. So, when Torino equalised on the half-hour, it came out of nowhere. An almighty goalmouth scrap from a corner was stabbed in by Barreto, with the partenopei unable to capitalise on their control.
After conceding, the visitors looked a lot less convincing. Torino were pressing for another goal, but left themselves exposed at the back. Napoli, the old counter-attacking masters, earned a penalty on a quick break inside the last ten minutes of the half. Christian Maggio was brought down in the area by a clumsy Matteo Darmian tackle, though Hamšík's spot kick was saved by the outstretched arm of goalkeeper Jean-François Gillet.
Napoli ended the second half on a low, but started the second very much on a high, as Džemaili netted his second with a perfect finish inside the area, rolling a smart Hamšík backheel into the bottom corner. They created more opportunities, though much as in the first half, they were made to pay for not taking them.
A handball by substitute Edinson Cavani in the box saw Jonathas score from the spot with a quarter-of-an-hour remaining, and Torino were once again level. They weren't done there, either, and three minutes later they had taken the lead. Another defensive error from Napoli allowed Torino sub Riccardo Meggiorini to round Antonio Rosati and slot into the empty net, as Toro took the lead for the first time.
They were pinned back instantly as Džemaili completed his hat trick from the edge of the area before, as if the result of a perfect piece of script-writing, Edinson Cavani atoned for his previous handball by curling a free-kick from the edge of the box perfectly into the back of the net.
This time, Napoli wouldn't relinquish their lead, and doubled it before the final whistle. Cavani netted his second after leaping to meet a Pablo Armero cross from the left, heading beyond Gillet to seal the victory.
Torino: Jean-François Gillet; Danilo D'Ambrosio (Salvatore Masiello 78), Guillermo Rodríguez, Kamil Glik, Matteo Darmian; Alessandro Gazzi, Migjen Basha; Mario Santana, Giuseppe Vives (Riccardo Meggiorini 56), Barreto (Jonathas 66), Alessio Cerci
Napoli: Antonio Rosati; Miguel Britos (Pablo Armero 79), Paolo Cannavaro, Alessandro Gamberini; Camilo Zúñiga, Blerim Džemaili (Rolando 88), Valon Behrami, Christian Maggio; Marek Hamšík; Goran Pandev, Lorenzo Insigne (Edinson Cavani 65)
Goals: Džemaili 10 (N) Barreto 30 (T) Džemaili 47 (N) Jonathas 75 pen (T) Meggiorini 78 (T) Džemaili 80 (N) Cavani 84 (N) Cavani 90 (N)