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.
In a brief statement to announce the appointment, the Madrid giants said Lopetegui had been appointed on a three-year contract.
Lopetegui will put to pen to paper on a three-year deal at the Bernabéu running until 2021, the club confirmed.
Work with the Spanish youth teams followed.
Previously, French manager Zinidine Zidane shocked the footballing world by announcing his resignation from Real Madrid.
"Julen Lopetegui will join the club after Spain's participation in the World Cup, after two years leading the national team".
Spain's senior side are unbeaten under Lopetegui, having won 14 and drawn six of their 20 matches and begin their World Cup campaign against Portugal on Friday.
His only other top-flight club experience came in 18 up-and-down months at Porto, where he failed to win a trophy but reached the Champions League quarterfinals. They also play Morocco and Iran in the group stages.
The ex-Porto manager is also no stranger to Real, with three years spent at the Bernabeu between 1988 and 1991 during his playing days and a period coming in charge of Real's "B" squad between 2008 and 2009.