Ancelotti, 61, has agreed a three-year contract with Madrid and will be presented in a news conference on Wednesday, the club said in a statement.
The Italian will replace his former assistant Zinedine Zidane, who resigned last week, at the Bernabeu.
"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," Ancelotti said in a statement.
"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."
It will be Ancelotti's second spell in charge of Madrid after taking the job in 2013 following Jose Mourinho's departure. The Italian won the Champions League, Copa del Rey, UEFA Super Cup and FIFA Club World Cup in two years at the club.
He was a popular figure at the club among both fans and executives, especially during his debut season.
His next piece of silverware was one of the most significant in the club's history, a Champions League -- his third as a manager -- won in Lisbon in May 2014, with a 4-1 victory against rivals Atletico Madrid after extra time.
The victory ended Madrid's 12-year wait for a 10th European Cup and secured Ancelotti's place in the club's record books. He also became the first manager to win the competition three times in the Champions League era. That achievement was later matched by Zidane, who led Los Blancos to three successive wins from 2016 to 2018.
However, the team's league form became more inconsistent -- they finished third in 2013-14 and second in 2014-15 -- and in his second campaign, there was criticism of Ancelotti's perceived relaxed managerial approach.