Lopetegui took over Spain in July 2016 after Vicente del Bosque retired from the role.
The Spanish giants broke the news in a Tweet on Tuesday.
Real Madrid were keen on appointing Spurs manager Mauricio Pochettino, but were put off by the hefty fee they would have had to pay for the Argentine after he recently signed a five year contract.
But following the conclusion of the tournament in Russian Federation, which La Roja are considered one of the favourites to win, Lopetegui will transition into the role at Santiago Bernabeu.
Julen Lopetegui will be the coach of Real Madrid after the 2018 World Cup in Russian Federation. Lopetegui spent part of his footballing career at Real Madrid, but only managed one senior appearance for the club. That U21 side featured the likes of David De Gea, Thiago, Koke and Rodrigo Moreno, all of whom have made it into the Spain squad for this summer's World Cup.
After retiring from football, Lopetegui became an assistant for Spain's U17 team in 2003, before swiftly taking charge of Liga B side Rayo Vallecano.
They face a World Cup group containing Iberian rivals Portugal, as well as Morocco and Iran.