King Felipe VI will on April 25th and 26th meet separately with the leaders of parties that won seats in parliament at an inconclusive December general election, the palace said in a statement.
If the parties are unable to propose a candidate for a prime minister with enough support to pass a vote of confidence in parliament, the king will dissolve the assembly and call fresh elections, it added.
The December 20th polls put an end to the traditional two-party system as voters fed up with austerity, unemployment and corruption scandals flocked to new parties, leaving a hung parliament divided among four main groupings, none of them with enough seats to govern alone.
The Socialists, who came second in the polls, formed a pact with centrist upstart Ciudadanos but they failed to secure enough support to form a government during two votes of confidence in parliament in March.
Socialist leader Pedro Sánchez has since then tried in vain to convince new far-left party Podemos to back a "government of change" that has the support of the Socialists, Podemos and Ciudadanos.
Talks between those three parties broke down last week, less than 24 hours before they began, due largely to the huge gulf between Ciudadanos and Podemos over economic policy and an independence referendum in the wealthy northeastern region of Catalonia.
Sánchez vowed on Tuesday to try "until the last minute, the last second" to reach an agreement.
"My hand remains extended. I will not give up," he added.
The Socialists were tasked with forming a government after acting Prime Minister Mariano Rajoy - whose conservative Popular Party came first at the polls but lost its absolute majority in parliament - gave up attempts to do so due to lack of support from other groupings.
A new government must be in place by May 2nd, otherwise fresh elections will be called for June 26th.
The king has so far held two unsuccessful rounds of talks since the December vote.