About 100 migrants tried to storm the barbed wire fence at dawn but Spanish and Moroccan security force prevented “around half” from entering Melilla, Spain's interior ministry in Melilla said in a statement.
One migrant was taken to a medical centre to treat cuts he suffered scaling the fence while four Spanish police officers sustained bruises, it added. Police arrested one of the migrants for assaulting an officer.
Video images published by local newspaper El Faro de Ceuta showed sweaters and jackets stuck to the razor wire that tops the border fence, left behind by the migrants.
The 52 who managed to enter Melilla were taken to a temporary migrant accommodation centre where they were given new clothes.
It was the biggest assault on the border between Melilla and Morocco since October 2018, when some 300 migrants stormed the fence. About 200 migrants managed to get into Melilla that time and one died of a suspected heart attack in the attempt.
Spain's two North African enclaves, Melilla and Ceuta, have the European Union's only land borders with Africa.
They are often used as entry points into Europe for African migrants, who either climb over their border fences or try to swim along the coast.