Spain sent its military to the Moroccan border on Tuesday and expelled nearly half of thousands of migrants who jumped fences or swam on to European soil over two days.
Morocco loosened border controls amid a deepening diplomatic dispute with Spain.
The sudden influx of migrants has created a humanitarian crisis for Ceuta, the Spanish city of 85,000 in North Africa on the Mediterranean Sea, separated from Morocco by a 10-metre-tall fence.
Some of those who reached Ceuta and were sent back to the Moroccan side accused the Spanish police of dispersing them with tear gas.
“We had arrived in Ceuta but they started shooting us with bullets,” said Taoufik Laarif, 24, who crossed on Monday night and was sent back to Morocco early on Tuesday.
Like Mr Laarif, hundreds of Moroccans and people from other African countries were trying to reach Europe.
Unemployment and the structural crisis deepened by the pandemic are the reasons Fatiha, the mother of two young men who crossed to Ceuta, gave AP.
“They did not find what to do here," Fatiha said. "There is nothing to do. The problem is the unemployment, plus the crisis. There is no work, nothing.
“We used to work in Ceuta but as you know it [the border] is closed. We used to sell many things in the streets there but all is blocked.
"Young people did not find anything to do. They hope to immigrate."
In Ceuta, overwhelmed soldiers separated the adults from the young and carried children in their arms, while Red Cross workers helped an endless trickle of migrants who were emerging from the water shivering and exhausted.
Spanish Interior Minister Fernando Grande-Marlaska denied that unaccompanied migrants under 18, who are allowed to remain legally under the tutelage of Spanish authorities, were being deported.
By Tuesday afternoon, nearly 8,000 people had swum across the border into the city since early Monday, the Spanish government said, including some 2,000 believed to be teenagers.
The number getting in slowed after Spain sent more police officers and soldiers, but the arrivals did not stop even when anti-riot police on the Moroccan side dispersed crowds of people hoping to cross over.
At least 4,000 were returned to Morocco, according to Spain’s Interior Ministry.
Spanish Prime Minister Pedro Sanchez cancelled a trip to Paris over the arrivals in Ceuta and will instead make an address after a regular Cabinet meeting on Tuesday.
"We will restore order in the city and in our borders as soon as possible," Mr Sanchez said.
He will visit Ceuta and Melilla, Spain's other north African enclave, on Tuesday.
The Interior Ministry said it would send an extra 200 police officers to increase security in the area. Spanish soldiers will also be sent to patrol its border.
Foreign Minister Arancha Gonzalez Laya told Cadena SER radio that Spain would “keep a cool head”.
She said both countries recently agreed that Spain would return anyone who entered Ceuta illegally by water.
The EU's home affairs chief, Ylva Johansson, described the influx as "unprecedented" and "worrying".
"The most important thing now is that Morocco continues to commit to prevent irregular departures, and that those that do not have the right to stay are orderly and effectively returned," she told the European Parliament.
"Spanish borders are European borders."
The president of Ceuta, Juan Jesus Vivas, told Cadena SER radio: “It’s such a strong invasion that we are not able to calculate the number of people who have entered.
“The army is at the border in a deterrent role, but there are great quantities of people on the Moroccan side waiting to enter.”
Mr Vivas, a conservative, said residents of Ceuta were in a state of “anguish, concern and fear”.
The influx comes at a time of tension between Madrid and Rabat.
Spanish media interpreted the mass crossing as a mark of Morocco’s discontent over the fate of Brahim Ghali, the leader of an insurgent group that wants independence for an area of the Sahara.
Mr Ghali is in hospital in Spain, a Spanish diplomatic source told Reuters.
Ms Laya said Morocco had assured Madrid that the rise in migrant arrivals was “not the result of the disagreement”.
“It was and is simply a humanitarian question, a humanitarian response to a request for humanitarian aid from a person who was in a very, very fragile health situation,” she said.
Morocco’s Foreign Ministry issued a strongly worded statement last month condemning Spain’s decision to let Mr Ghali in under a false identity without informing Rabat.
It said Spain’s decision would have repercussions for relations between the countries.
Figures published by the Spanish Interior Ministry show that between January 1 and May 15, 475 migrants reached Ceuta by land or sea, more than double the 203 who arrived in the same period last year.