(Bloomberg) -- Spain and Morocco are ready to overcome years of strained diplomatic relations with new business and energy deals, while ties between France and the North African nation remain frosty.

Prime Minister Pedro Sanchez is planning to announce Thursday an €800 million ($869 million) credit line for Spanish investments in Morocco and 20 agreements that range from developing renewable energy to building water desalinization plants.  

“Morocco can play a key role as the gateway for Spanish companies into Africa,” Sanchez said Wednesday evening, kicking off a two-day visit in Morocco’s capital.

Speaking after him, Morocco’s Prime Minister Aziz Akhannouch said the visit is expected to facilitate gas deliveries through a currently idle pipeline that connects the two countries. 

Western European nations are racing to shore up relations with key security and energy allies in Africa after Russia’s invasion of Ukraine, to counter the growing influence of both Russia and China across the continent.

Sanchez visit also consolidates the warming links between the neighbors after Sanchez last year unexpectedly dropped his country’s decades-long neutrality policy to back Morocco’s plan for limited autonomy for Western Sahara, a former Spanish colony rich in phosphate resources and offshore fisheries.

His reversal ended a migration crisis that saw thousands of people cross into the Spanish north African enclave of Ceuta in a matter of days in May 2021. At the time Madrid claimed Morocco eased border controls as retaliation for authorities allowing the head of a group fighting for Western Sahara’s independence to be treated for Covid-19 at a Spanish hospital. 

The controversial shift in position frayed ties with Algeria, a key gas supplier that supports the Polisario’s armed struggle for independence of the disputed territory. It also raised tensions with Sanchez’s junior coalition partner, the far-left Unidas Podemos. None of the Podemos ministers joined Sanchez on his visit. 

Shaky Ground

While ties with Madrid have been normalized, Morocco’s relations with France, one of its top investors, remain on shaky ground over the return of irregular immigrants and visa restrictions. French President Emmanuel Macron had been planning on traveling to Morocco during this quarter, but the visit has yet to be confirmed.

Allegations that Morocco was involved alongside Qatar in an influence-peddling scandal at the European Parliament have also raised tensions with Brussels. Moroccan lawmakers voted last week to review ties with the European Union after the parliament approved a resolution condemning the country’s human rights record. Sanchez’s Socialist Party refused to back the resolution. Both Morocco and Qatar have denied corruption allegations.

Morocco is Spain’s main investment destination in Africa with annual trade of nearly €17 billion, according to Spanish government data. Only China and the US rank ahead of Morocco among Spain’s top trade partners outside the EU.

Spain has pushed Morocco to let trade of goods from the enclaves of Ceuta and Melilla resume after it was stopped over diplomatic tensions. Spanish authorities said they are working to gradually reopen customs in Melilla and inaugurate a new customs office in Ceuta to stamp out smuggling.

Human rights groups have for years denounced the exploitation of thousands of women who carry contraband goods from the Spanish enclaves across the border to Morocco.

Stretching along the Atlantic coast and rich in minerals, Western Sahara is larger than the U.K. and has been bitterly contested since its 1975 annexation by Morocco after the Spanish withdrawal. Sporadic fighting between Moroccan forces and the independence-seeking Polisario Front claimed about 9,000 lives over 16 years. A cease-fire that had held for three decades collapsed in late 2020.

--With assistance from Ania Nussbaum and Samy Adghirni.

(Updates with quotes from Spain’s PM Sanchez and Morocco’s PM Akhannouch)

©2023 Bloomberg L.P.