Morocco security forces clashed with the migrants, leaving 27 people wounded, they added.
Ninety-six migrants were arrested, while about 100 managed to cross over, the officials said.
Melilla is a major crossing point for sub-Saharan Africans seeking work or asylum in Europe.
Together with a second Spanish enclave, Ceuta, it is the European Union's only land border with Africa.
Many of those making the dangerous journey come from Eritrea and Somalia.
The Moroccan interior ministry said the migrants hurled rocks at the security forces as they stormed the six-metre (20-foot) high double barbed wire fence on Monday.
Thirteen security force members and 14 migrants were wounded in the clashes, it added in a statement.
A Spanish government spokeswoman said the migrants were "very violent" and had targeted two different sections of the border fence, the AFP news agency reports.
About 150 African migrants made it into Melilla after a similar assault on the border fence on 17 February.
At least 14 migrants drowned in Moroccan waters on 6 February while trying to enter Ceuta by sea.
Spain's interior ministry confirmed on Friday that police fired rubber bullets as the migrants swam into Spanish territory, but denied the shooting contributed to the drowning.
At least 300 African migrants have stormed a border fence in an attempt to cross into the Spanish territory of Melilla from Morocco, officials say.