The migrants managed to get around the border fence where it meets a breakwater on the Mediterranean shore of Ceuta, the Spanish government delegation there said in a statement.
Some of the migrants that tried to make it through in the early morning dash for the border were held back by Moroccan security forces.
Of the 87 that managed to cross, some breached the fence while others went into the sea and swam around the breakwater, the statement said.
Eleven of the migrants said they were minors, it added. The migrants were all in good health, though 10 of them and three Spanish police officers were treated for light injuries.
Along with Melilla to the east, Ceuta is one of two Spanish territories on the northern coast of Morocco that together form the European Union's only land borders with Africa.
Meanwhile, almost 200 migrants from North and sub-Sahara Africa were rescued overnight as they tried to reach southern Spain in makeshift vessels, Spanish coastal rescue officials said on Sunday.
"Maritime rescue services picked up 188 people from seven craft," a spokesman told AFP.
A Red Cross spokesman told AFP that 103 Algerians, half of them minors, were aboard five craft off the southern port of Almeria.
Two other vessels were crammed with 85 sub-Saharan Africans.
In this latter group, one craft was intercepted off Spain's Alboran island and the other off the Andalusian coast, opposite the northern Moroccan port city of Al-Hoceima.
Four of the sub-Saharan migrants were hospitalised, two of them pregnant women.
According to the International Organization for Migration, 2,819 migrants crossed the narrow strait to Spain from North Africa between January and the end of September.
Thousands of migrants have tried to reach Spain from north Africa.
Many try to smuggle themselves across the border to Ceuta and Melilla hidden in cars while others cross the Mediterranean in flimsy boats.