“The law is not designed for events such as the stampedes in Ceuta and Melilla,” Interior Minister Jorge Fernández Díaz said last week.

These days military vehicles rumble down the roads near the fence around Melilla, and helicopters hover above, on constant patrol. The shelter here is so overcrowded that men like Mr. Cisse sleep in triple bunks, 15 of them in a space no bigger than a college dorm room.

Even so, their excitement is hard to miss because they are well on their way to getting what they hoped for. Most have had brutal journeys and now will probably spend a year or more in the immigration center as their applications for asylum are processed. Few will get such status. But most will end up transferred to the mainland before being handed an order to leave Spain.

Most cannot be deported because Spain does not have treaties with many of the countries they come from. So in the twist that has confounded Europe’s efforts to secure its borders for decades now, many of those who make it to Melilla and Ceuta will be largely free to remain in Spain or other European nations that offer them the prospect of better lives.

Nobody knows exactly why, after nearly a decade of relative quiet, the pressure on Ceuta and Melilla has started again, but Spain’s economic crisis may have something to do with it. Spanish officials here acknowledge that Spain has lately had to cut back on aid to Morocco, which has in recent years kept sub-Saharan Africans from getting too close to the enclaves.

The central Spanish government delegate to Melilla, Abdelmalik el Barkani, said he doubted the loss of aid had much to do with it. The recent surge probably had more to do with human traffickers, he said.