The 16-year-old forward, who has previously been compared to Neymar, will remain in Brazil before moving to Real in July 2019.
A brief statement from the Primera Division side read: "Real Madrid C. F. and Clube de Regatas do Flamengo have reached an agreement regarding the transfer of the federative rights of the player Vinicius Junior from July 2018.
"The player will remain at his current club until July 2019, although he will be able to play for Real Madrid before then if both clubs agree to it."
Vinicius, who made his senior debut for Flamengo in a league game against Atletico Mineiro recently, is reportedly costing the Spanish champions £39.6m.
Real added on their website: "A skillful, pacy attacker who is able to go past players and has an eye for goal, Vinicius Junior excelled in the Flamengo academy and for the Brazil youth teams.
"In 2015, he lifted the South American Under-15 Football Championship staged in Colombia, at which he netted six goals. In March of this year, he repeated the trick by claiming glory with the U17 team in Chile, where he was named player of the tournament and ended the competition as the leading goalscorer, with seven goals to his name."