The Italy striker, who previously played for Milan's rivals Inter, returns to San Siro on a four-and-a-half-year contract.
City confirmed Balotelli's exit on their website and the 22-year-old, who won the FA Cup and the Premier League in his two full seasons but made many headlines for his disciplinary problems, thanked manager Roberto Mancini for standing by him.
Mario Balotelli: "I love Roberto, he has been very important for my career, and I will always thank him for having trust and faith in me.
"Being at City was an important part of my life and career. I needed to grow up like a player and as a person and it has been a very good experience for me.
"I will remember, too, the song that City fans had for me. It was special for me and I always liked to hear it. I hope they can still sing it sometimes.
"I will always be interested in Manchester City and their fortunes. I really hope that City can win the league again this year and beat United. I think there are great players at the club and a great manager too."
Roberto Mancini: "We are very sorry for him because he leaves the club but we hope Mario can continue to improve and continues to work hard because he is a top, top player."
Source: Manchester City MAD