Pedro Sanchez of the Spanish Socialists has become the latest party leader to be asked to try and form a government, after December’s inconclusive polls.
His party came second but the outgoing Prime Minister, Mariano Rajoy of the centre-right Popular Party (PP), failed to secure a parliamentary majority.
Two new parties, the radical left Podemos and the centrist Ciudadanos, made big gains in the December vote.
Along with smaller regional parties, they hold the balance of power.
King Felipe VI formally invited the leader of the Socialists (known in Spain by the abbreviation PSOE) to try and form a government.
Announcing his acceptance, Mr Sanchez said talks would begin on Wednesday with all parties on forming a coalition to create a “stable government backed by constitutional forces”.
The PP won 123 seats to 90 for the PSOE, 69 for Podemos and 40 for Ciudadanos, in the 350-seat parliament.
Having ruled out a grand coalition deal with the PP alone, Mr Sanchez needs the support of both Podemos and at least one more party to obtain a working majority in parliament.
However there are sharp differences between Podemos and Ciudadanos, and the PSOE’s opposition to independence for the restive Catalonia region makes any deal with Catalan nationalist parties, who together have 17 seats in parliament, unlikely.
If no working government can be formed, a fresh general election will be called.
Last month, Mr Rajoy turned down an offer by King Felipe to be the first candidate to try to form a government, saying he did not have the support to win a confidence vote in parliament.
It is the first time in 40 years that the monarch has had such an influential role after an election. For decades the PP and PSOE alternated in power with secure majorities.
The former King, Juan Carlos, oversaw Spain’s democratic transition after the death of nationalist dictator General Francisco Franco in 1975.
Spain country profile
Uncertain future for Spain after election