Partenopei president Aurelio De Laurentiis (h/t sports writer Jack Rathborn) announced the news via Twitter.
Per Football Italia, Hamsik posted on Instagram after the news became official. He apologised for not being able to say goodbye in person but hopes he'll still have the chance:
"I've tattooed 'Napoli' on my skin, as well as our first victory in the Coppa Italia after 25 years. It's impossible to forget that game.
"It's impossible to forget that moment when I beat Bruscolotti's record or when I broke the Azzurri's goal record, set by the god of football himself, Diego Armando Maradona.
"That makes me extremely proud. Here in Naples, my three children were born, Neapolitans in every way.
"I'd like to thank everyone: the President who gave me the possibility of staying here for 12 years and accepting my willingness to try a new experience; all the coaches who trained me, to whom I owe my growth as a player and as a man; all the medical and technical staff and everyone else at SSC Napoli; my friends who I'll miss, but I know they'll never leave me because they're part of my family.
"As soon as it's possible, I hope you'll grant me one last lap around the field at the San Paolo, to dedicate to you the send off you deserve."
In the 31-year-old's time in Naples, he became the club's all-time top scorer and appearance leader.
He was linked with a switch to China in the last month, but issues with the payment saw the proposed move suspended.
Those problems have now been cleared up, however, and the Slovakia international will team up with Yannick Carrasco and Nicolas Gaitan at the ambitious Chinese Super League club.
Like those two, Hamsik is still in his prime. The midfielder made 12 starts for Napoli in Serie A this season, while also starting five of their six Champions League fixtures.
He joined the Partenopei from Brescia in 2007 and played a key role in their rise back up the Serie A pecking order, guiding the side to two Coppa Italia titles.
Ruiz's emergence means Napoli already have the perfect replacement in their ranks. The Spaniard has combined well with Allan so far and will slide into the starting XI alongside the Brazilian.