However, they have now chose to appoint Lopetegui, who signed a new two-year extension with the Spanish Football Federation (RFEF) last month.
In May, he signed a two-year extension to remain as Spain coach until 2020 but the call of Madrid has proved stronger.
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.
Lopetegui will take over a Real Madrid side who have dominated in Europe but finished a distant 17 points behind champions Barcelona in La Liga last season.
In an official statement on the club's website, it was confirmed that the current Spain manager will replace Zinedine Zidane as first team coach after the tournament in Russian Federation.
He coached Madrid's feeder club Castilla in 2008/09 before taking charge of Spain's youth teams. Lopetegui spent part of his footballing career at Real Madrid, but only managed one senior appearance for the club. Spain will face Iran and Morocco in Group B after the challenge of Cristiano Ronaldo's Portugal in their opener on Friday.
Lopetegui, 51, was hired by Spain following their underwhelming Euro 2016 campaign and the former Porto boss has helped re-establish La Roja as genuine contenders this summer in Russian Federation.