Mazzarri announced his departure immediately after the end of their final game of the season against Roma.
"I won't be the coach of Napoli next season," Mazzarri, whose side had already clinched second place, told RAI television.
"I think I've got the most out of this group of players," he added following a 2-1 defeat.
The 51-year-old, a former journeyman midfielder who spent most of his playing career in the lower leagues, said that a clean break would be best for everyone.
"My cycle at Napoli has ended," he said. "They have been four fantastic years, I want to thank the lads and everyone who has been close to me.
"Napoli is a great club to work at and I'm leaving because I need a new challenge and so do the players."
Last season, forward Ezequiel Lavezzi left the club for Paris St Germain and there is speculation that talismanic striker Edinson Cavani could also be bought by one of Europe's big-spending clubs.
The Uruguayan finished the season as Serie A topscorer with 29 goals.
"I took this decision a while ago," said Mazzarri.
"I think I've brought Napoli as far as they can go, and I think this is the right time to leave.
"Fabio Capello has said that a coach in Italy cannot stay at the same club for more than four or five years and I think the players need something new."
The club confirmed on their website that Mazzarri was leaving.
Mazzarri also led Napoli when they made their Champions League debut last season, reaching the last 16.
- Sports & Recreation