MÁLAGA, Spain — Spain’s new Socialist government has waded straight into Europe’s migration crisis — out of both choice and necessity.

Shortly after taking office in early June, Prime Minister Pedro Sánchez won plaudits from aid groups for welcoming to Spain 630 migrants from the Aquarius, a rescue ship that had been turned away by Italy and Malta. But at home, Mr. Sánchez is under pressure to stem a sudden influx of migrants crossing from Morocco on inflatable boats.

The number of unauthorized migrants arriving in Europe from Africa, the Middle East and Asia has fallen sharply since 2016 — except in Spain, where it has soared.

Spain’s situation underlines its reliance on Moroccan authorities to stop migrants who try either to cross the Strait of Gibraltar or to climb the fences that surround Spain’s two enclaves in North Africa, Ceuta and Melilla. The increased flow has raised concerns in Spain that Morocco may have deliberately relaxed surveillance along its beaches facing Spain.