Julen Lopetegui is out as Spain’s manager. (Gabriel Bouys/AFP/Getty Images)

In a stunning announcement made just two days before its country’s first World Cup match against Iberian rival Portugal, the Spanish Football Federation (RFEF) fired Coach Julen Lopetegui over his decision to take the head-coaching job at Real Madrid without informing the country’s soccer officials that he was even considering it.

“We have been forced to dispense with the national coach. We wish him the greatest of luck,” RFEF President Luis Rubiales told reporters at the team’s World Cup training headquarters, per the Guardian. “The negotiations [with Real Madrid] have occurred without any information to the Spanish FA and we were informed just five minutes before the news release. There’s a way to act that needs to be fulfilled.

“You can’t do things this way, two or three days before the World Cup. We have been compelled to make this decision,” Rubiales also said, according to the BBC.

Rubiales added that he spent Wednesday morning conferring with Spain’s players, who urged him to keep Lopetegui on during the World Cup. But he was unmoved, with reports suggesting he was furious at Lopetegui and upset that Real Madrid ignored his hurried request to delay the announcement until after the world soccer tournament.

“There are decisions that we are obliged to take based on an understanding of how you should behave and on ethics,” he said.

Spain named Fernando Hierro as its World Cup coach later Wednesday. A well-decorated player for both Spain’s national team and Real Madrid — he appeared in four World Cups, two European Championships and won three Champions League titles — Hierro was the national team’s sporting director in the run-up to the World Cup. He previously was an assistant coach at Real Madrid and manager of Spanish second-division club Real Oviedo.

Want smart World Cup analysis, opinions, viewing guides and more? Sign up for our month-long newsletter.

Real Madrid, a European club titan that has won the UEFA Champions League in three straight seasons, announced Tuesday that Lopetegui would replace Zinedine Zidane after the World Cup was over. Zidane announced his surprising resignation two weeks ago.

Lopetegui replaced Vicente del Bosque as Spain’s manager after it didn’t make it out of group play at the 2014 World Cup and failed to defend its European Championship title in 2016. Del Bosque had led La Roja to a nearly unprecedented run of success, with its 2010 World Cup championship sandwiched between European titles in 2008 and 2012.

Featuring a talented midfield and one of the world’s best goalkeepers in David de Gea, Spain is one of the favorites to win this year’s World Cup. It has not lost a match since a 2-0 loss Italy in the European Championships round of 16 nearly two years ago. Now it will proceed with a void at the top, with Lopetegui’s permanent replacement yet to be determined.

“We are going to touch as little as possible. We are working on it. When we know we will tell you,” said Rubiales, who flew from Moscow — where the vote for the 2026 World Cup host was being held — to Spain’s training base in Krasnodar, Russia. “I have spoken with the players and I can guarantee they will do everything, along with the new coach, to take the team as far as possible. To win is very important, to have the best coach very important, but above everything is acting in the right way. Maybe this is tough now, but in the end it will make us stronger. …

“We had to react, I know that whatever I do I will be criticized, I accept that.”

More World Cup coverage:

World Cup 2018 schedule and results

Take our quiz: How much do you know about World Cup hosts?

World Cup 2018 rosters: Every team, every player

Can Russia, with its history of racist attacks and hooligans, put on a World Cup welcome?

Perspective from one of the Men in Blazers: Soccer is here to stay in America, World Cup berth or not

A die-hard soccer fan lands dream assignment: A Russia 2018 World Cup newsletter

This American World Cup superfan will surpass his 150th match in Russia this summer