A statement on the Real Madrid website confirmed the Brazilian will join on a six-year deal this summer, with the fee, via a buy-out clause in the player's Port contract, thought to be around €50m (£42.7m).
It read: "Real Madrid and Porto have agreed the transfer of the player Éder Militão, who will be linked to the club during the next six seasons, until June 30, 2025."
Militao only joined Porto last summer, joining from Sao Paulo for just over £6 million.
But the 21-year-old has impressed enough to be drafted in as competition for Sergio Ramos and Raphael Varane at the Bernabeu.
Also able to play at right-back or in midfield, Militao has one Brazil cap so far in his career.
Militao's Porto have advanced further than Madrid in this season's Champions League.
The Dragoes beat Roma in the last 16 and will be in the draw on Friday, while Madrid were shocked by Ajax.
Join our commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies