Migrants climb the fences separating the Spanish enclave of Melilla from Morocco in Melilla, Spain, Friday, June 24, 2022. AP
Melilla and Ceuta, Spain's other tiny North African enclave, have the European Union's only land borders with Africa, making them a magnet for migrants.
Some 2,000 migrants made their way to the border at dawn and over 500 managed to enter the border control area after cutting a fence with shears, the Spanish government's local delegation said in a statement.
Of these 130 sub-Saharan African migrants, "all of them men and apparently adults", managed to enter Melilla, it added.
Morocco deployed a "large" amount of forces to try to repel the assault on the border, which "cooperated actively" with Spain's security forces, the delegation said earlier in a separate statement.
Images on Spanish media showed exhausted migrants laying on the sidewalk in Melilla, some with bloodied hands and torn clothes.
On Thursday night migrants and security forces "clashed" on the Moroccan side of the border, Omar Naji of Moroccan rights group AMDH told AFP.
Morocco's Hassani Hospital in Nador near Melilla confirmed that "several" police officers and migrants were admitted for treatment.
In March this year, Spain ended a year-long diplomatic crisis by backing Morocco's autonomy plan for Western Sahara going back on its decades-long stance of neutrality.
Spanish Prime Minister Pedro Sanchez then visited Rabat, and the two governments hailed a "new stage" in relations.
The row began 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 Spain's Ceuta enclave as border guards looked the other way, in what was widely seen as a punitive gesture by Rabat.
Rabat calls for Western Sahara to have an autonomous status under Moroccan sovereignty but the Polisario wants an UN-supervised referendum on self-determination as agreed in a 1991 ceasefire agreement.
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
'Means of pressure'
Patching up a relationship with Morocco, the departure point for many migrants has meant a drop in arrivals, notably in Spain's Atlantic Canary Islands.
The number of migrants who reached the Canary Islands in April was 70 percent lower than in February, government figures show.
Sanchez earlier this month warned 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 June 29-30.
Over the years, thousands of migrants have attempted to cross the 12-kilometre (7.5-mile) border between Melilla and Morocco, or Ceuta's eight-kilometre border, by climbing the fences, swimming along the coast or hiding in vehicles.
The two territories are protected by fences fortified with barbed wire, video cameras and watchtowers.
The attempts include violent clashes between those crossing and the agents charged to stop them.
Migrants sometimes use hooks and sticks to try to climb the border fence, and throw stones at police.
Claimed by Morocco, the two cities have long been a flashpoint in diplomatic relations between Rabat and Madrid, which insists both are integral parts of Spain.