Ancelotti arrived at Goodison Park as a replacement for Marco Silva in December 2019 and led the club to 10th position in his only full season in charge.
The former AC Milan, Chelsea and Paris Saint Germain manager arrives in the Spanish capital on a three-year contract.
Real Madrid were in the market for a new manager after Zinedine Zidane stepped down from his role at the end of the 2020/2021 season.
Ancelotti famously led Real Madrid to their 10th Champions League crown in the 2013/2014 season but was dismissed the following campaign.
An Everton club statement read: "Everton can confirm that Carlo Ancelotti has left his position as manager to take up the role of Head Coach at Real Madrid."
"Everton would like to place on record its thanks to Carlo for his service to the Club over the past 18 months.
"The Club will begin the process of appointing a new manager immediately and will provide updates in due course."
In a statement on Everton's website, Ancelotti said: “I would like to thank the board of directors, the players, and the Evertonians for the tremendous support they have all given me during my time at the club.
“I have complete respect for everyone associated with Everton and hope they can achieve the exciting opportunities they have in front of them. While I have enjoyed being at Everton I have been presented with an unexpected opportunity which I believe is the right move for me and my family at this time.”