"This is the most important day and at the same time one of the most difficult of my sporting career, the time has come to say goodbye," Casillas wrote in a letter posted on Twitter.
"I have been very fortunate to make a career out of something that I am passionate about, something that fills me and makes me happy.
"My football career started 30 years ago and it has been a long path and like any journey, it's had its good times and sad times. Looking back and at this stage of my life, I can say it's been well worth it."
Casillas went on to thank Real Madrid and Porto as well as all of his teammates and coaches.
"Real Madrid wants to show its recognition, admiration and affection for one of the biggest legends of our club and of world football," a statement from the La Liga side read.
"The best goalkeeper in the history of Real Madrid and Spanish football joined us at the age of nine.
"He was formed here and defended our shirt for 25 years, becoming one of our most emblematic captains of all time. Iker Casillas earned the love of Madridismo and is a symbol of the values that Real Madrid represents."
Casillas won the Champions League on three occasions at Madrid and also helped them to five La Liga titles, two Copa del Rey triumphs, the Spanish Super Cup four times as well as the UEFA Super Cup, FIFA Club World Cup and Intercontinental Cup and two occasions each.
Lo importante es el camino que recorres y la gente que te acompaña, no el destino al que te lleva, porque eso con trabajo y esfuerzo, llega solo y creo que puedo decir, sin dudar, que ha sido el camino y el destino soñado #Grac1as pic.twitter.com/xb8ucs9REh— Iker Casillas (@IkerCasillas) August 4, 2020
His 177 Champions League appearances remains a record and he earned 167 caps for Spain, who he captained to World Cup glory in 2010, sandwiched in between two European Championship successes in 2008 and 2012.
Casillas' last game was a 2-2 league draw at Rio Ave on April 26, 2019 -- his 156th game since joining Porto on a free transfer in the summer of 2015.
He served as an intermediary between players and coaching staff at Porto in the 2019-20 season before his contract with the Portuguese champions expired last month.
Casillas had considered the possibility of running for president of the Royal Spanish Football Federation (RFEF) but recently stated he would not do so due to the coronavirus pandemic.
He is in advanced talks to return to Real Madrid as an advisor five years after his exit from the club.