At least 6,000 migrants have reached Spain's Ceuta enclave from neighbouring Morocco, a record number over a single day, Spanish officials say.
They say the migrants - who include about 1,500 minors - either swam around the border fences that jut out into the sea or walked across at low tide.
They are said to be mostly from Morocco. Spain says it has already sent some 2,700 back - but not the minors.
Spain's Ceuta and Melilla enclaves have become magnets for African migrants.
Spanish troops have been deployed to the beach to help border police at Ceuta's main entry point - Tarajal, on the enclave's south side.
Interior Minister Fernando Grande-Marlaska said 200 troops, plus 200 extra police were going to assist Ceuta's normal 1,100-strong border force. The enclave has some 80,000 inhabitants.
Later, Moroccan security forces at Fnideq, the adjacent town, fired tear gas to disperse a large crowd of migrants at the border fence, AFP news agency reported.
Prime Minister Pedro Sánchez has cancelled a trip to Paris - he was to attend a French-led summit on financial aid for Africa. Instead, he is focusing on the Ceuta crisis, and he promised "maximum firmness" in restoring normality to the enclave.
At the other enclave, Melilla, 86 sub-Saharan Africans entered on Tuesday via its southern jetty, which marks the border with Morocco.
Melilla has a formidable border fence, and several hundred more migrants were blocked by security forces, Spain's Efe news agency reports.
Spanish officials quoted by Efe said Moroccan guards had helped the Spanish forces in Melilla. Some migrants threw stones at the Spanish forces, they said.
Spanish media said it was different in Ceuta, where Moroccan border guards stood by and watched as migrants took to the sea to try to reach the enclave.
Most of the migrants were said to be young men, but there were also several families. Many had used inflatable rings and rubber dinghies.
They started arriving in Ceuta at 02:00 (midnight GMT) on Monday, but the number soared during the day. At least one died during the crossing.
Last month, more than 100 migrants arrived at Ceuta's Tarajal entry point. Most were sent back, except about 30 minors whose ages were confirmed by medical tests.
Since the 17th Century both Ceuta and Melilla have been under Spanish rule, though they are long claimed by Morocco. The port cities now form the EU's only land border with Africa. They have semi-autonomous status, like some regions of mainland Spain.
The influx comes amid renewed tension over Western Sahara, a territory occupied by Spain until 1975, when Morocco annexed it. Since then it has been disputed between Morocco and the indigenous Sahrawi people, led by the Polisario Front.
Souring of ties over Western Sahara
In April, Spain allowed Sahrawi leader Brahim Ghali, 73, to be treated in hospital for Covid-19, reportedly in Logroño. He leads the Polisario Front, fighting for Western Saharan sovereignty against the claims of Morocco. The Moroccan government responded angrily and warned Spain that harbouring Mr Ghali would bring "consequences".
Spanish Foreign Minister Arancha González said she was not aware of Morocco using the border issue to exert political pressure. But many see Monday's events, when Moroccan border guards appeared not to stop migrants from crossing, as evidence of a reprisal.
Such difficulties are likely to complicate the two neighbours' normally tight co-operation on the migrant issue. However, Spain says it has already repatriated about half of the migrants, following talks with Morocco.
The vast majority of those who reached Ceuta were Moroccan. Local police have clamped down on sub-Saharan migrants in northern Morocco in recent years, meaning they have sought other routes to Spain, such as across the Atlantic to the Canary Islands.
The EU border force Frontex reports that illegal migration to Spain's Canary Islands - off the Moroccan coast - has surged this year.
In most cases sub-Saharan Africans make perilous journeys in rickety boats and drowning is common.
However, the overall number of undocumented migrants reaching Europe so far this year remains far below the levels seen in 2015-2016.
Read more on migrants reaching Spain: