Real Madrid have announced that Iker Casillas' 725-game stay with the club is at an end.
The Spanish club said on their official website that they had agreed a deal with Porto for their 34-year-old captain.
Casillas joined Real's youth academy in 1990 and has been with the club ever since, winning 17 major honours in that time.
Real saluted Casillas in a lengthy statement, referencing a "goodbye of a million sensations" and hailing him as their best-ever goalkeeper.
"We have agreed the transfer to the Portuguese club for Iker Casillas," Real said.
"For Real Madrid today is a day, before and above all, for an acknowledgement.
"This will not be one of the best goalkeepers at our club - it is the best goalkeeper in the history of Real Madrid and Spanish football.
"This is therefore a goodbye of a million sensations, full of hopes, dreams, sacrifices and wins.
"Iker Casillas has made our shield even bigger. He was our captain and has defended our goal for 25 years."

Manchester United have confirmed that Matteo Darmian has completed his transfer from Torino, signing for the club on a four-year contract with the option to extend for a further year.
25-year-old Darmian made 146 appearances and scored five goals for Torino, and 13 international caps for Italy.
The defender said it was a dream come true to sign for United.
"To work with Louis van Gaal, a manager that has achieved so much in football is such an exciting prospect," Darmian said.
Aston Villa midfielder Fabian Delph has ruled out a move to Manchester City and insisted he will stay with Tim Sherwood's side.
Delph did not fly out with the rest of the Villa squad for their training camp in Portugal on Thursday amid strong speculation that he was poised for an £8million move to the Etihad Stadium.
But Delph on Saturday released a statement via Villa's website to dismiss the story.
"I'm aware there has been intense media speculation surrounding my future in the last 24 hours and I want to set the record straight," Delph said.
"I'm not leaving. I'm staying at the football club and I can't wait for the start of the season and captaining this great football club."
Delph was on Manuel Pellegrini's radar as City are keen to boost their home-grown quota following the loss of James Milner to Liverpool and Frank Lampard to New York City.
Delph signed a new Villa contract earlier this year with his previous deal having been due to expire this summer, but it had been reported that City would meet a release clause in that contract.
His re-commitment to the cause will come as a major boost to Sherwood, who has signed two players from City - Scott Sinclair and Micah Richards - as well as midfielder Idrissa Gueye from Lille this summer.
Stoke look set to announce the signing of former Liverpool right-back Glen Johnson as they continue their summer recruitment drive.
No deal has been officially confirmed but Stoke boss Mark Hughes admitted on Saturday morning that the 30-year-old England international's experience would be a valuable addition to the squad.
Speaking to Sky Sports from Stoke's pre-season tour to Singapore, Hughes said: "Glen's a very experienced player, we obviously feel that the qualities that he has will help us.
"We're a team that's trying to progress and you do that by getting good players into your squad and they will help us.
"Glen has played at a high level for a very long time and we can benefit from that."

Johnson is a free agent after being released by Liverpool when his contract ran out at the end of last season.
The right-back spent the last six years at Anfield having previously played for Portsmouth, Chelsea, Millwall and West Ham.
He has won 54 caps for England since making his debut in 2003 and was part of Roy Hodgson's squad at last summer's World Cup.
The capture of Johnson would follow the arrivals of Shay Given, Marco van Ginkel, Joselu, Philipp Wollscheid and Jakob Haugaard this summer as Stoke look to build on last season's ninth-placed finish in the Barclays Premier League.
"We expressed an interest, we put a bid in, but we needed really to set a deadline"
The Potters had also been looking to bring in Inter Milan's Xherdan Shaqiri but Hughes says the club have now "stepped aside" in their pursuit of the Switzerland international and turned their attention elsewhere.
Hughes said of the 23-year-old: "We expressed an interest, we put a bid in, but we needed really to set a deadline.
"We've got other irons in the fire and sometimes if you invest too much time in one deal, then you can lose others. That was the case with this one so we've stepped aside and we're looking at other things now."
While Stoke have been busy bringing in reinforcements, they have seen Steven Nzonzi leave for Europa League winners Sevilla this week and look set to lose goalkeeper Asmir Begovic to Chelsea.
Asked the latest on the Begovic situation, Hughes said: "I haven't had an update today but my understanding is that he's likely to travel to Chelsea and that will be concluded."
Hughes also backed the Bosnia and Herzegovina international to push Thibaut Courtois hard for the number one jersey if he joins the Premier League champions and not just settle for a back-up role.
"I would imagine, having worked with Asmir, that he'll back his ability and he would think he will challenge and get game time there, or he wouldn't have gone there," the former Chelsea striker said.
"He's a confident goalkeeper and a very accomplished goalkeeper so he'll push whoever's in the number one very, very hard."
Celta Vigo have snapped up former Manchester City striker John Guidetti on a free transfer.
The 23-year-old, who spent last season on loan at Celtic, has signed a five-year deal with the Spanish club.
"The Swedish striker John Guidetti, a target for leading clubs in various European leagues, has joined the exciting project of Real Club Celta," the club said in a statement.
"The striker, who has signed a five-year contract, will be presented on Sunday."