Endrick -- who is 16 and will move to Madrid when he turns 18 in July 2024 -- is one of the most exciting young talents in Brazilian football.
Palmeiras said the terms of the deal would remain confidential, but sources told ESPN that the teenager will join Madrid on an initial three-year contract with the option of a three-year extension, for a transfer fee worth a total of €72 million including variables and taxes.
"Real Madrid, Palmeiras, Endrick and his family have reached an agreement that allows the player to join Real Madrid when he reaches legal age in July 2024," Madrid said in a statement on their website.
"Until then, Endrick will continue training with Palmeiras. The player will travel to Madrid in the upcoming days to visit our club's facilities."
"We've finalised the biggest negotiation in the history of Brazilian football," Palmeiras president Leila Pereira said. "Real Madrid's proposal is compatible with Endrick's enormous talent and corresponds to the sporting and financial goals that we have established since the beginning of the talks."
Madrid have targeted the Brazilian market in recent years in a strategy led by the club's chief scout, Juni Calafat, agreeing deals for Vinicius Junior in 2017, Rodrygo in 2018 and Reinier Jesus in 2020.
Vinicius and Rodrygo have both gone on to become key first-team players at the Bernabeu, playing important roles in Madrid's LaLiga and Champions League double last season.
Madrid have been looking for a young forward who could eventually replace star striker Karim Benzema, who is 34.
Endrick made his debut for Palmeiras' first team in October at the age of 16.
He became the youngest goal scorer in the club's history when he found the net twice against Athletico Paranaense on Oct. 25 and helped the team win the 2022 Brasileirao Serie A title, with three goals in seven appearances.
"I thank Palmeiras for offering me everything necessary to become what I am today, helping to achieve my dreams and respect my wishes and those of my family," Endrick said.
"Until I join Real Madrid, I will continue to dedicate myself as I always have, to being able to offer Palmeiras even more on the pitch."