Algeria on Sunday is planning to halt shipments through the Gaz-Maghreb-Europe (GME) pipeline, which has been carrying almost 10 billion cubic metres (bcm) per year.
The pipeline, which traverses Morocco before crossing the Mediterranean at the Strait of Gibraltar, is a victim of the crisis in relations between Algeria and Morocco.
With Algeria having severed diplomatic ties with Morocco in August, a renewal of the pipeline contract that expires on Sunday is unlikely, threatening one of Spain's main sources of gas.
With technical constraints limiting alternative sources and the risk of further price increases, Spain "finds itself in a complicated situation" even if "the risk of shortages is limited," said Gonzalo Escribano, an energy expert at the Elcano think tank in Madrid.
He called the decision "bad news ... at a bad moment" for Spain, which depends on Algeria for half of its natural gas needs.
Despite a big push into wind and solar, Spain remains dependent on imported energy.
What will the impact of GME's closure be on Spain?
Spain's Ecological Transition Minister Teresa Ribera sought to sound reassuring during a meeting in Algiers earlier this week, speaking of "arrangements taken to continue to assure, in the best way, deliveries of gas through Medgaz according to a well determined schedule".
Medgaz is a second pipeline that runs directly between Algeria and Spain under the Mediterranean.
It can carry eight bcm a year, and planned works could see its capacity reach 10.5 bcm.
Algeria also proposes increasing deliveries of liquefied natural gas (LNG) by sea.
'Theory and practice'
"On paper, it is enough to ensure the same level of deliveries. But there is theory and practice, and Spain isn't safe from bad surprises," said Thierry Bros, a specialist on the geopolitics of energy who teaches at Sciences Po university in Paris.
Work on increasing the capacity of Medgaz is expected to last into December.
"Valves need to be changed, tests conducted ... You can't rule out delays," Bros said.
But he believes the main problem to be with LNG, which is transported by special ships that keep the gas very cold so it remains condensed in liquid form.
"It could be complicated to find such ships, especially at the moment when there is strong demand for gas in Asia" and shipowners prefer the most profitable routes, Bros said.
And given that Spain has limited storage capacity but plenty of LNG gas terminals, the risk is less about a shortage than the price paid.
"The country will manage to cope" with potential supply problems, "but that will have an impact on the price", said Escribano, noting that gas transported by ship is more expensive than that by pipelines.
In recent months natural gas and LNG prices have soared as the global economy gears back up.
In addition to homes linked to the gas network for heating and cooking, Spain is also reliant on gas-fired power plants and electricity prices have already shot higher.
Soaring energy prices are weighing on Spanish consumers who have already been battered by the coronavirus pandemic, and the government has already moved to temporarily lower electricity taxes.
In one sign the situation is concerning, Spain has recently reached out to its other LNG suppliers -- the United States, Russia and Qatar -- in order to ensure deliveries, according to a source close to the discussions.
Meanwhile, local operators are also making preparations to receive additional supplies.
Enagas, which operates four LNG terminals and the national gas grid, has opened up extra slots for ships.
"We are doing everything possible to contribute to the security of gas supplies," its president, Antonio Llarden, said earlier this week.
Meanwhile the Spanish government is emphasising the preparations that are being made.
"We've increased the level of reserves" and "the capacity to receive LNG ships", Ribera said in a radio interview on Friday.
Ribera said she believes the risk of electricity blackouts this winter to be "very limited".