Algeria said Wednesday it was suspending a decades-old co-operation treaty with Spain, after Madrid backed the position of the North African country's arch-rival Morocco on the disputed Western Sahara.

"Algeria has decided to immediately suspend the treaty of friendship, good neighbourliness and co-operation," the Algerian presidency said in a statement.

Madrid and Algiers had signed the deal in 2002 to promote dialogue and cooperation on political, economic, financial, education and defence issues.

A Spanish diplomatic source told AFP that the government of Pedro Sanchez "regrets the Algerian decision".

Algeria's move came in retaliation after Spain in March publicly recognised Morocco's autonomy plan for the disputed territory, helping end a year-long diplomatic spat between the two kingdoms.

But Algeria said Wednesday that Spain's move had been "in violation of its legal, moral and political obligations" towards the territory, a former Spanish colony.

That reflects the complex challenge Madrid faces in balancing its ties with both states, bitter rivals.

Algeria, which backs the Polisario movement seeking independence in the Western Sahara, had in August last year broke off diplomatic ties with Rabat over "hostile acts".

Morocco controls 80 percent of the Western Sahara.

The rest is held by the Polisario, which fought a 15-year war with Morocco after Spanish forces withdrew in 1975 and demands a referendum on independence.

People walk along a market street in Western Sahara's main city of Laayoune in November 2018
People walk along a market street in Western Sahara's main city of Laayoune in November 2018 AFP / FADEL SENNA

Morocco has offered limited autonomy but insists the phosphate and fisheries-rich enclave must remain under its sovereignty.

Spain officially endorsed that position in March to help resolve a year-long diplomatic dispute sparked by a visit by Polisario leader Brahim Ghali to Spain for treatment for Covid-19.

Weeks after his hospitalisation, Moroccan border forces looked the other way as more than 10,000 migrants surged into Spain's tiny North African enclave of Ceuta, an incident seen as meant to pressure Madrid.

In April Sanchez made an official visit to Morocco to patch up ties after his government backed Rabat's 2007 autonomy plan.

Algiers said Wednesday that Madrid had thereby "given its full support to an illegal and illegitimate formula... advocated by the occupying power".

Spain's position is complicated because while it shares borders and strong economic ties with Morocco, it also depends partly on Algeria for natural gas.

That dependence that has become more acute as energy prices exploded following Russia's invasion of Ukraine, but also because Algeria in October last year stopped pumping gas to Spain through a pipeline traversing Morocco.

And in a veiled warning to Morocco, Sanchez said Wednesday that "Spain will not tolerate any use of the tragedy of illegal immigration as a means of pressure."

"The best way is international cooperation," he said.

Algeria and Morocco have seen months of tensions since Morocco re-established ties with Israel in December 2020 in exchange for Washington also recognising Rabat's sovereignty over the Western Sahara.

That came just weeks after the Polisario had declared a 1991 ceasefire null and void, stepping up attacks on Moroccan forces.