If Spain fail to impress at the World Cup, then Lopetegui will head to Real Madrid under a cloud that will make an already difficult job even harder.
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.
A former goalkeeper, Lopetegui made one senior appearance for Real Madrid but played 107 matches for Logrones.
He was appointed to the role in the wake of Spain's poor showing at Euro 2016 in France when they were eliminated in the last 16. Lopetegui is now in Russian Federation preparing the Spanish squad for the World Cup.
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.
Lopetegui is now preparing to lead Spain at the World Cup but the 51-year-old will depart his role as national team coach at the end of the tournament.
Before he took over as Spain boss, Lopetegui was Porto manager for two years.
The 51-year-old, who has been in charge of the national team for the past two years, has agreed a three-year contract at the Bernabeu.
Zidane's resignation came as a big shock, as he had just led Real Madrid to a third consecutive UEFA Champions League triumph.
But Madrid had finished a distant third as Barcelona took the honours in LaLiga, and Lopetegui will be charged with closing what was a 17-point gap.