Carlo Ancelotti has said his bond with Real Madrid is "eternal" as he prepares to leave the Spanish club this weekend to become head coach of the Brazil national team.
The Brazilian Football Confederation (CBF) announced earlier this month that it had reached an agreement for Ancelotti to take over as national team boss starting May 26.
Confirming the news, Real said Ancelotti's tenure at the Santiago Bernabeu would come to an end after Saturday's home game against Real Sociedad.
"Our club would like to express its gratitude and affection to one of the greatest legends of Real Madrid and world football," Real Madrid said in a statement.
Club president Florentino Perez added: "We are incredibly proud to have had a coach who has helped us achieve so much success and who has at the same time embodied the values of our club in such an exemplary way."
Ancelotti has won 15 trophies in two spells as Real manager, including the Champions League and La Liga titles last season.
His first spell was between 2013 and 2015, with his second beginning in 2021 after he arrived from Everton.
The 65-year-old's contract with Real was due to expire in June 2026 but his departure has been brought forward, and he will start his new job on Monday.
"I carry in my heart every moment of this magnificent second spell as Real Madrid manager," Ancelotti wrote on X.
"An incredible journey, full of emotions, titles and, above all, the pride of representing this club.
"What we have achieved together will remain forever in the memory of every Real Madrid fan, not only for the victories, but for the way we won them. The magic nights at the Bernabeu are now part of football history.
"Now, a new adventure begins, but my bond with Real Madrid is eternal."
Xabi Alonso, who played for Real Madrid, Liverpool and Spain, is being lined up to replace Ancelotti.
The 43-year-old Alonso has confirmed he will leave Bayer Leverkusen, and Real are keen to get him in place before next month's FIFA Club World Cup gets underway.
Brazil turned to Ancelotti after sacking Dorival Junior following a 4-1 defeat to Argentina in March.
The Selecao are fourth in the South American group, having lost five of their 14 games, but are still well placed to qualify for the 2026 finals.
Ancelotti's first games as Brazil boss will be World Cup qualifying matches against Paraguay and Ecuador in June.