MADRID — Pedro Sánchez and his Socialist party won Spain’s national elections in April. If only it were that easy. Nothing now is straightforward in Spanish politics, where winning is relative in a polarized and fragmented landscape.

The Socialists secured the most seats in Parliament, but fell short of a majority. So this week, Mr. Sánchez must finally turn in earnest to the challenge of assembling a governing coalition. If he fails, Spaniards will face the prospect of another election — the fourth since late 2015.

His task will not be easy. The coalition negotiations have already led to bitter and often personal feuding, and Mr. Sánchez must rely on smaller parties.

Mr. Sánchez’s surprisingly strong result in April was seen as a victory for Socialism in Europe. It also came as a relief to backers of the European Union, which he and his party support, at a time when the bloc is embattled by challenges from nationalists and populists, especially in Italy and Eastern Europe.