“The migrants demonstrated a hostile and violent attitude. Many were armed with sticks and they attacked the officers when they tried to prevent them from entering,” the Spanish government's representative in Ceuta said in a statement.
Three policemen and 32 migrants were treated in hospital for minor injuries, the statement said.
The migrants were taken to a short-stay immigrant centre while Spanish authorities determine their legal status, a local police spokesman said.
Police were also searching for a handful of others who made it across the barbed-wire fence and fled into the surrounding hills.
Ceuta along with Melilla, another Spanish territory in North Africa, have the European Union's only land borders with Africa.
They are favoured entry points for African migrants seeking a better life in Europe, who get there by either climbing over the border fence or by swimming along the coast.
In 2014, 15 migrants drowned as dozens tried to swim to Ceuta from a nearby beach.
At the time, human rights groups and migrants said Spanish police tried to keep them from reaching the shore by firing rubber bullets and spraying them with tear gas.