The 33-year-old will be paid €1.5 million ($1.8 million) for the 2021-22 and 2022-23 football seasons each.
He will also get €700,000 ($850,000) signing bonus for each season.
Trabzonspor put a video on Twitter to announce their new signing. Hamsik, wearing a gladiator helmet and the team's classic striped shirt, is walking toward the pitch with a football in his hand.
He has also played for Italy's Brescia and Napoli, China's Dalian Professional and Swedish club Goteborg.
He spent most of his time at Napoli (2007-2019), scoring 121 goals and producing 100 assists in 520 appearances. He won two Italian Cups and one Italian Super Cup with the Naples team.
The Slovakian national team regular with 26 goals in 126 international caps will represent his nation in the UEFA EURO 2020, set to begin on Friday.