Ceuta's population is just 84,000, but an estimated 60,000 migrants entered the territory between Wednesday and Friday, according to Ceuta's top official, Juan Jesus Vivas. The Spanish interior ministry put the figure at 50,000.
By late morning Saturday, "almost all" had left and the situation had practically returned to normal, said Spain's Interior Minister Fernando Grande-Marlaska.
He added that at least 67 people had died trying to reach Ceuta.
One possible explanation for the migrants' movement could be Spain's Supreme Court ruling on July 8 that migrants arriving by sea should not be returned as quickly as others.
Spanish officials stressed that, under Schengen Area rules, Ceuta and Melilla, another Spanish enclave, have specific procedures applying border controls for anybody boarding air or sea transport to mainland Europe.
They said irregular entry into Ceuta does not confer a right to remain in Spain, travel to the mainland, or move freely throughout Europe.
Meanwhile, hundreds of anti-migrant protesters rallied outside Morocco's embassy in Madrid on Friday evening to denounce what they called a migrant "invasion" of Spain’s north African enclave of Ceuta.
Some demonstrators carried a large banner reading "Remigration"—a term promoted by several far-right groups in Europe referring to the forced or encouraged return of migrants or people of immigrant background.
Despite the barrier to any of the migrants heading to mainland Europe, Italy announced Friday that it was suspending Schengen rules allowing border-free travel with Spain. Madrid condemned the move, though its practical impact remains unclear given the two countries do not share a border.
France and Britain expressed "solidarity" with Spain, but France also announced a fivefold increase in police deployed at its border with Spain.
Portugal also said it would strengthen controls at its southern land and maritime borders.
U.S. President Donald Trump, who has made anti-immigration policies a centerpiece, called the migrant influx into Ceuta a "catastrophe" and an "invasion" on Friday.
He sought to tie it to midterm elections he faces in November, saying, "That same thing's going to happen to us if the Republicans don't get elected, except worse, much bigger."