Endrick is a teenager from Palmeiras.
The 16-year-old forward will join the European and Spanish champion in July 2024.
Under the age of 18 is not allowed to be transferred abroad.
Endrick will be visiting his new club in Spain next week, but Palmeiras and Real Madrid did not reveal the length of the contract.
Endrick told the Palmeiras website: "I thank Palmeiras, forever the club of my heart, for offering me everything necessary to become what I am today, for helping me to accomplish several of the my dreams and for respecting my desire and that of my family to make another dream come true.
Until I join Real Madrid, I will devote myself to being able to offer Palmeiras more on the field.
Endrick is both a player and a goal scorer.
The teenager has scored three goals in seven Brazilian games.
The president of the Brazilian club said that they had finished the largest negotiation in the history of Brazilian football.
The sporting and financial goals that we have established since the beginning of negotiations are compatible with Real Madrid's proposal.