(Bloomberg) -- Spain’s energy minister secured a commitment from Algeria to reroute natural gas supplies and meet demand after flows through a key pipeline crossing neighboring Morocco stop next month.

In a last-minute visit to Algiers on Wednesday, Ecological Transition Minister Teresa Ribera received assurance that Algeria will ship gas via the separate Medgaz pipeline across the Mediterranean Sea and supplement it with liquefied natural gas, according to a statement from the ministry. 

An accord on transit via the Maghreb-Europe pipeline through Morocco expires on Oct. 31 amid a diplomatic spat between the two North African nations, which makes renewal of that agreement unlikely at this stage. 

Europe is facing an energy crunch, with gas and power prices breaking records several days this year. Supplies via the Medgaz route mean it’s less likely that Spain will face a harsh winter, since traders hadn’t booked capacity to flow gas through the Maghreb-Europe link next month, according to data published by the Spanish network operator Enagas SA. 

“The total guarantee has been made explicit with respect to the volumes agreed today,” Ribera said in the ministry’s statement. While no details on volumes were released, it said Spain and Algeria discussed how “to ensure that everything also works in the smoothest and best possible way.”

Algeria, Spain’s biggest gas supplier, committed to comply with contracts signed by Spanish and Algerian companies, the statement said.

Toufik Hakkar, chief executive officer of Algerian state-run energy company Sonatrach Group, declined to comment on the Maghreb link in a telephone interview earlier Wednesday. He said that Algeria would prioritize shipments to its traditional partners.

“Priority will be given to our historical partners with whom we are linked by pipelines,” Hakkar said. “The most important thing for us is the market share, not the price. Our efforts are directed towards meeting the needs of our historical partners.”

Spain is struggling with a surge in energy prices that’s already prompted the government to cut taxes to soften the blow to consumers. The jump in costs has also boosted inflation and forced factories to curb output, threatening the economic recovery.

Flows via the Maghreb pipeline will continue at reduced levels through Sunday, after which no shipments are planned, according to the Enagas schedule.

(Updates with comments from Spain’s ecological transition minister throughout.)

©2021 Bloomberg L.P.