The 33 year old made his debut in 1995 and is expected to complete a move to Turkish side Besiktas in the next couple of days.
He said at a press conference in Madrid: “Thank you to everyone. I go knowing that Real Madrid will always be my home.
“I leave knowing that Real Madrid wants me and that is very important.”