The search to replace Zinedine Zidane, who left after guiding Real to a third-straight Champions League title, lasted nearly two weeks, with Mauricio Pochettino, Antonio Conte and Jurgen Klopp among the names reportedly in the frame.
Lopetegui took over Spain in July 2016 after Vicente del Bosque retired from the role.
However, they have now made a decision 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 Russian Federation, which La Roja are considered one of the favourites to win, Lopetegui will transition into the role at Santiago Bernabeu.
Lopetegui is now in Russian Federation preparing the Spanish squad for the World Cup.
After guiding Spain easily through qualification to the World Cup finals, Lopetegui had agreed on a new contract up until Euro 2022 just last May, and was not among the more than 20 names which had been linked with the Bernabeu vacancy in the local media over the past two weeks.
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.
They face a World Cup group containing Iberian rivals Portugal, as well as Morocco and Iran.
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.
He has previously coached Spain's youth sides and had two years in charge of Porto.
- Ghost of Tsushima makes its gameplay debut at E3 2018
- Microsoft drops official technical support for older products on community forums
- What Liverpool have planned for Xherdan Shaqiri transfer is rather interesting
- Leaders tweet own angles on 'spontaneous' G7 moment
- Battletoads Coming to Xbox in 2019
- New Game+ mode is coming to God of War
- Assad denies Russia makes decisions for him
- Facebook's Memories is a dedicated spot for nostalgia
- Latest in Popular Video Game Series to Be Set in West Virginia
- German ministry says 774000 Mercedes cars contain unauthorized software