Hakimi, 21, spent the past two seasons on loan at Borussia Dortmund, forging a reputation as one of Europe's best attacking full-backs.
"Real Madrid and Inter Milan have agreed the transfer of Achraf Hakimi," a statement from Real Madrid said.
"The club want to thank Achraf for all these years of dedication, professionalism and exemplary behaviour since he arrived at our academy in 2006 and wish him luck in this new stage of his career."
He was unwilling to return to the Bernabeu as an understudy to Dani Carvajal and opted for a move to Inter over interest from a number of Premier League clubs, as well as Bayern Munich and Dortmund themselves on a permanent deal.
Hakimi is a Real Madrid youth product who made his first-team debut under Zinedine Zidane in October 2017 before joining Borussia Dortmund on loan in July 2018.
He became a key first-team player at the German club, making 54 Bundesliga appearances and scoring seven goals.
The Morocco international is likely to feature for Inter as a right wing back, with coach Antonio Conte favouring a 3-5-2 formation, but can also play as a full-back or winger on either flank.