Real had been heavily linked with a number of potential managerial appointments following the shock resignation of Zinedine Zidane, including Tottenham boss Mauricio Pochettino and former Spurs and Porto manager Andre Villas-Boas.
However, they have now decided to appoint Lopetegui, who signed a new two-year extension with the Spanish Football Federation (RFEF) last month.
But following the conclusion of the tournament in Russia, which La Roja are considered one of the favourites to win, Lopetegui will transition into the role at Santiago Bernabeu.
A statement read: “Julen Lopetegui will be the coach of Real Madrid after the 2018 World Cup in Russia.
“Real Madrid CF announces that Julen Lopetegui will coach the first team for the next three seasons.
“Julen Lopetegui will join the club after the participation of the Spanish team in the World Cup, after two years leading the national team.”
Lopetegui will go head-to-head with Cristiano Ronaldo at the tournament, with Spain set to take on Portugal in their opening group game this Friday. They also play Morocco and Iran in the group stages.
Zidane resigned as manager following an unprecedented era of success that saw Real win three consecutive Champions League titles, most recently defeating Liverpool 3-1 in Ukraine to complete the treble.
The France legend subsequently took the decision to step down, and a replacement has now been found, though expectations are unlikely to be any lower.
Lopetegui has endured a mixed managerial career thus far, but has history with Los Blancos, having managed the club’s B team between 2008 and 2009.
A trusted youth coach, he has also managed Spain at Under-19, Under-20 and Under-21 level, though he failed to win any silverware at FC Porto and was sacked.
It remains to be seen if he will head to Real as a World Cup winner, though Spain’s squad is stocked with exciting talent