The 33-year-old Belgian defender joined the club in the summer of 2008 and has made 360 appearances, winning four Premier League titles, two FA Cups, four League Cups and two Community Shields.
He signed off with victory in the FA Cup final on Saturday, where City thrashed Watford 6-0 to complete a domestic treble.
“As overwhelming as it is, the time has come for me to go. And what a season to bow out,” said Kompany, who joined City from Hamburg.
“I feel nothing but gratefulness. I am grateful to all those who supported me on a special journey, at a very special club.”
Kompany added: “I will never forget how all Man City supporters remained loyal to me in good times and especially bad times. Against the odds you have always backed me and inspired me to never give up.
“(Club owner) Sheikh Mansour changed my life and that of all the City fans around the world, for that I am forever grateful. A blue nation has arisen and challenged the established order of things, I find that awesome.”
Kompany also paid tribute to his team-mates and manager Pep Guardiola.
“It’s cliche to say it but it’s also so true: without my team-mates, I would have never been here today,” he said.
“We fought many battles together. Side by side. In good times and in bad. So to all of you, from the 2008-2009 squad to today’s domestic treble winners: I owe you guys!
“A special word also to Pep and the backroom staff: you’ve been superb. You’ve followed me through so much hardship. You made me come back stronger every time. Thank you so much.”
For more news your way, download The Citizen’s app for iOS and Android.
Download our app and read this and other great stories on the move. Available for Android and iOS.