Lacking a majority in parliament and facing elections next year, the 54-year-old Socialist prime minister responded to wildfires near Madrid by appealing for unity in curbing human-driven climate change.

Within days, a fresh political challenge erupted, with tens of thousands of migrants pouring into Spain's north African territory of Ceuta, alarming his European allies.

"I don't think his handling of the fires affected the prime minister's image," as opposition-run regions were responsible for fire prevention, said Paloma Román, a political scientist at Madrid's Complutense University.

"But the migrant crisis -- that has put it much more in doubt. They themselves said they didn't see it coming... that's very negative for the government."

Sánchez - a figurehead for some progressives internationally - will see his government put on the spot Tuesday by EU ministers.

READ ALSO: EU chief praises Spain's 'swift handling' of Ceuta migrant rush

They will hold an emergency meeting over the 50,000 or more migrants who rushed into Ceuta -- images of whom were widely shared online by far-right groups.

The crisis prompted Donald Trump's US administration to accuse Madrid of enabling irregular migration.

European fracture

Images of flames ravaging tens of thousands of hectares and forcing whole villages to evacuate dominated the news for days from July 23rd.

A week later, they were replaced by scenes of migrants swimming around the border barrier between Morocco and Ceuta and running into the city.

"These are crises of a different nature," Mariam Martínez-Bascunan, a professor of political science at the Autonomous University of Madrid, told AFP.

"The fires stem from a structural climate emergency, while the other is a form of coercion linked to Morocco," which some commentators said may have used the migrants for diplomatic pressure on Spain, she said.

Almost all of the roughly 50,000 migrants who entered Ceuta irregularly last week have since returned to Morocco.

But their brief entrance sparked broad alarm among Sánchez's political rivals and strained relations within the European Union.

The European right and far right, led by Italy's Prime Minister Giorgia Meloni, accused him of laxity at the borders.

Meloni's government, led by her far-right party, suspended visa-free travel with Spain -- although Ceuta is not part of the EU's open-border zone.

"What the Ceuta crisis reveals is not that Pedro Sánchez has personal enemies within the EU, but something far more serious," said Martínez-Bascunan.

"Ceuta has shown that the European world is falling apart... because everyone retreats to their own interests whenever a crisis proves useful to them."

Election stakes

With a general election due in 2027, the conservative main opposition Popular Party (PP) and far-right Vox seized on the Ceuta crisis as an opportunity to shift the fight against Sánchez "onto the international stage", Roman said.

Under Sánchez, who has resisted Trump over the Iran war and challenged Israel over the deaths of Palestinians in Gaza, "foreign policy has carried far more weight than under previous governments", she added.

"Beyond the PP and Vox, he also has powerful adversaries on the international stage."

The twin summer crises followed several difficult months for Sánchez on the domestic front, with several corruption scandals implicating his family and party.

Roman of the Complutense University said the Ceuta crisis "served as fuel" for the PP and Vox.

Regarding the fires, political scientist Fernando Vallespin, a former head of the public polling body CIS, pointed out that the PP governs the regions worst affected by the recent fires.

In voters' minds, "the PP therefore appears implicated as possibly jointly responsible for the neglect of rural areas," he told AFP.

Article by Robin BJALON and Roland LLOYD PARRY