RABAT, MOROCCO - Madrid and Rabat seem ready to overcome years of tense diplomatic relations with new business and energy deals, while ties between France and the North African kingdom remain frosty at best.

On Wednesday, Madrid and Rabat held their first bilateral summit in eight years to strengthen economic ties and build on a diplomatic truce that was established last year to overcome disputes regarding migration and territory.

Spain's Prime Minister Pedro Sanchez and 12 members of his cabinet will meet their counterparts in Rabat Thursday to sign 20 agreements to boost trade and investment and bring the two countries closer together in areas beyond migration.

Sanchez announced on Thursday an €800 million ($869 million) credit line for Spanish investments in Morocco, mainly in developing renewable energy.

Madrid is seeking to turn the page on a dark history with Rabat stained with regular diplomatic crises, most recently the storming by 8,000 migrants of Spain's north African enclave of Ceuta in 2021 after Morocco relaxed border controls.

The event was widely seen as a response to Madrid's decision to host secretly Brahim Ghali, leader of the Polisario Front rebel group which seeks to establish an independent state in Western Sahara, to enter Spain for medical treatment.

"The new era in our ties is thanks to your government's position regarding our southern provinces. Spain had the courage of historical realism. And for that, Morocco pays homage to you," Moroccan PM Aziz Akhannouch told his Spanish counterpart during the Morocco-Spain Summit on Wednesday.

In March 2022, PM Sanchez restored cordial ties with Rabat after he reversed Spain's four-decade policy of neutrality regarding Western Sahara by backing Morocco's proposal to create an autonomous region.

The decision cost Madrid the friendship of Algeria the main backer of the Polisario Front, which suspended, in a revenge move, the Maghreb–Europe Gas Pipeline (GME) that was the critical gas supplier for Rabat and Madrid.

Some observers argue that Madrid chose, at least for now, migration over energy, as it started to diversify its sources of gas supplies and end its dependence on Algerian gas.

"Approaching Morocco means moving away, at least as far as the Sahrawi conflict is concerned, from Algeria, a key gas supplier for Spain. This change of course is part of a larger geopolitical context," Christiane Waked, a Spain-based columnist and a political analyst, told The New Arab.

In June last year, Madrid reactivated the gas pipeline in the opposite direction to supply Morocco with gas despite Algeria’s refusal.

Sanchez has also shown interest in investing in Morocco's green hydrogen as Spain vows a greener economy.

While Spain could move from its dependence on Algeria's gas, its over-reliance on Moroccan control of their shared borders seemed a key influence for its current diplomacy.

Last June, Morocco demonstrated its key role in migration control when its law enforcement quelled an attempted mass border crossing into Melilla, Spain's other North African enclave, in a move that left at least 23 people dead and scores injured.

Madrid has hailed a general drop in migration numbers, both to the Spanish archipelago and via the Western Mediterranean route, significantly as migrant arrivals to Europe via other Mediterranean routes increase.

Preserving Rabat's friendship has pushed Sanchez's Socialists into uncomfortable positions such as voting against a resolution in the European Parliament to call on Morocco to improve its record on press freedom.

Moroccan diplomats and media have accused France, a staunch ally of the kingdom, of "orchestrating" the anti-Morocco European Parliament resolution.

After Rabat and Paris vowed to "write a new page together" last December, the Moroccan-French ties apparently slipped into renewed crisis as French FM Catherine Colonna refused to take "a clear" stand on the Western Sahara issue during her visit to Rabat.