Lopez was Madrid's first-choice goalkeeper in the league last season ahead of long-serving Iker Casillas but found his position under threat following this summer's signing of Costa Rica's World Cup goalkeeper Keylor Navas.
The 32-year-old has now decided to leave Spain for this first time in his career after agreeing a four-year deal with Milan, bringing an end to his second spell at the Bernabeu.
Lopez, who came up through the youth ranks at Madrid before returning to the club in 2013 following spells at Villarreal and Sevilla, has written an open letter where he revealed his pride at having had the chance to represent the 10-time European champions and giving thanks to everyone at the club.
The letter on Real's website read: "Thirty-two years ago, I was born in a small village in the province of Lugo, Paradela. I dreamed about being a footballer, but I never imagined that I would one day play for the club of my heart, Real Madrid. It is something that I will always be proud of.
"For an academy player to return to the club of their life is the greatest thing.
"I leave happy, because I have given my all. My only objective was to work day upon day with respect, dedication and to passionately defend the values of the best club in the world.
"For all of this I can say with great pride that every minute I spent with Real Madrid was like a gift sent from the heavens."