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.”