One migrant died in the melee, after falling of the seven-meter high border fence, while 34 others were injured, including 12 security personnel.
Some 200 migrants succeeded in getting over the fence into Melilla, and were transferred to a reception center for processing.
According to Moroccan authorities, the rest who did not make it would be deported to their home countries.
Morocco is accessible to some African nationals visa-free, and has become a main gateway for migrants into Europe since Italy imposed stringent measures including increasing patrols along the Libyan coastguard.
The number of migrants departing from Libya has since decreased significantly.
More than 6,000 migrants have made it to Melilla and Spain’s nearby territory Ceuta so far this year, according to the U.N. refugee agency UNHCR.
Others pay smugglers to get them across the 14 km (9 miles) of sea to Spain.
The vast majority of arrivals in Spain are men, primarily from Guinea, Mali and Morocco, the UNHCR says.