The leaders said the previous MidCat pipeline project across the Pyrenees would be abandoned.
Spain and France have struck a new deal to build an underwater gas pipeline from Barcelona to Marseille, cancelling a long-stalled pipeline project that would have connected the countries through the Pyrenees.
The pipeline will allow Spain and Portugal, two leading importers of liquefied natural gas (LNG), to bring their excess supplies to France and other European countries.
LNG has become the go-to commodity to replace the vast volumes of Russian gas that the Kremlin has cut off since launching the invasion of Ukraine.
The European Union is trying to secure as much LNG as commercially possible in order to make it through the winter without major power blackouts or gas rationing.
The deal was announced on Thursday by Spanish Prime Minister Pedro Sánchez, French President Emmanuel Macron and Portuguese Prime Minister António Costa, ahead of an EU summit in Brussels, where the energy crisis will be the top topic.
"This is very good news for Europe," Sánchez told reporters, before heading into the meeting. "This solidarity is coherent with our green transition."
"The objective is to be better connected to the rest of the continent for Spain and Portugal," Macron said.
The deal means that the MidCat project is officially abandoned, the leaders confirmed.
The 226-kilometre-long pipeline was supposed to connect Spain's gas network to France's by crossing through the Pyrenees, from Hostalric, in Catalonia, to Barbaira, in Southern France.
MidCat had been stalled since 2019, when an independent report cast doubt over the pipeline's price and profitability. But the war in Ukraine and the subsequent energy crisis injected new momentum and fuelled calls from Madrid and Lisbon to complete the project.
Macron, however, remained opposed, arguing the pipeline was too costly, unaligned with the EU's green ambitions and unable to transport electricity.
The French leader also said that two existing pipelines that cross from Spain into France through the Basque Country were being used only at "50% to 60%" of their total capacity.
The German government of Chancellor Olaf Scholz, which is seeking to replace Russian gas, also pushed for the pipeline's completion. Thursday's deal puts an end to the months-long tensions.
Instead of the underground MidCat, the countries will build a brand-new underwater pipeline, dubbed BarMar, connecting Barcelona with Marseille.
The infrastructure could be operational by the end of the decade, officials told Euronews.
The pipeline will initially carry gas, a polluting fossil fuel that contributes to climate change, but will be gradually filled with green hydrogen and other "renewable gases," although the commercial viability of these products is still an open question.
At the same time, Spain and Portugal commit to finish another gas interconnection, named CelZa, between Celourico da Beira and Zamora.
Additionally, Spain and France will aim to complete a new electricity connection through the Bay of Biscay, while working to identify similar projects.
Sánchez, Macron and Costa will meet again on 9 December to determine the financing details of the BarMar project. The Spanish government had previously suggested that any new connection with France would require EU funds due to its cross-border dimension.