The Spanish prime minister has described a deadly migrant rush on the enclave of Melilla from Morocco as an attack on Spain's "territorial integrity", as human rights activists demanded an investigation.

At least 23 African migrants died in the latest drama on the doors of the European Union, when around 2,000 mostly sub-Saharan African migrants approached the Moroccan border with the tiny territory at dawn on Friday.

More than 500 managed to enter a border control area after cutting a fence with shears, Melilla authorities said in a statement.

Moroccan officials said 23 migrants had died during the rush or succumbed to their injuries, some of which came from falling from the top of the barrier.

Authorities said that 33 migrants and two security force personnel remained in hospital but in "stable condition" on Saturday in the cities of Nador and nearby Oujda.

Spanish Prime Minister Pedro Sanchez said the incident was a "violent and organised attack by mafias who traffic in human beings, against a Spanish territory".

But Morocco's AMDH human rights group said it was "a true catastrophe that shows the consequences of the latest Moroccan-Spanish entente", just weeks after the two sides resolved a year-long diplomatic rift.

The death toll is by far the worst recorded in years of attempts by migrants to cross into Melilla, one of Spain's North African enclaves which have the EU's only land borders on the continent.

Images on Spanish media on Friday showed exhausted migrants lying on the pavement in Melilla, some with bloodied hands and torn clothes.

By Saturday, calm had returned to the border area, with Moroccan security forces lightly deployed and no migrants to be seen.

The International Organization for Migration and the UN refugee agency expressed "grave concern at the lives lost and the number of injured".

The agencies reminded member states of the "need in all circumstances to prioritise the safety of migrants and refugees, to avoid excessive use of force and to respect their fundamental rights."

In Morocco, the AMDH demanded a "comprehensive, quick and serious enquiry", while the Democratic Labour Organisation (ODT) trade union urged the government "to investigate this tragedy and do what is needed" both for migrants and police.

In Spain, Sanchez's left-wing coalition partner Podemos also called for a probe.

Residents fear attacks

Residents of the Barrio Chino neighbourhood on the Moroccan side of the barrier said they were in shock.

"This is the most violent attempt to cross into Melilla that I've ever seen," said Rachid Nejjari, a waiter in a cafe near the heavily fortified border fence.

"I saw migrants armed with sticks and iron bars... I was afraid of being attacked."

Friday's was the first mass incursion since Spain mended a year-long rift by backing Morocco's autonomy plan for the disputed Western Sahara region, scrapping its decades-long stance of neutrality.

Sanchez then visited Rabat, and the two governments hailed a "new stage" in relations.

The row had begun when Madrid allowed Brahim Ghali, leader of Western Sahara's pro-independence Polisario Front, to be treated for Covid-19 in a Spanish hospital in April 2021.

A month later, some 10,000 migrants surged across the Moroccan border into the Ceuta enclave as border guards looked the other way, in what was widely seen as a punitive gesture by Rabat.

Rabat wants Western Sahara to have autonomous status under Moroccan sovereignty but the Polisario insists on a UN-supervised referendum on self-determination as agreed in a 1991 ceasefire deal.

Migration 'security threat'

In the days just before Morocco and Spain patched up their ties, there were several attempted mass crossings of migrants into Melilla, including one involving 2,500 people, the largest such attempt on record. Nearly 500 made it across.

The mending of ties has meant a drop in migrant arrivals in Spain, notably in the Canary Islands.

The number of migrants who reached the Canary Islands in April was 70% lower than in February, government figures show.

Sanchez said earlier this month that "Spain will not tolerate any use of the tragedy of illegal immigration as a means of pressure."

Spain will seek to have "irregular migration" listed as one of the security threats on NATO's southern flank when the alliance gathers for a summit in Madrid on 29-30 June.

Over the years, thousands of migrants have attempted to gain entry to the Spanish enclaves by climbing the barriers, swimming along the coast or hiding in vehicles.

The two territories are protected by fences fortified with barbed wire, video cameras and watchtowers.