(Bloomberg) -- Spain’s Pedro Sanchez accepted an invitation from King Felipe VI to try to form a government, giving the acting prime minister just weeks to convince Catalan separatists to hand him the votes he needs to secure a third term.

The Socialist leader now faces tough negotiations as pro-independence parties step up their demands in return for support in a confidence vote to be held in less than two months.

“We will work to piece together not only a majority for the investiture, but a legislative majority that gives the country stability for the next four years,” Sanchez told reporters, adding that he will start talks on Wednesday.

Conservative People’s Party leader Alberto Nunez Feijoo, who did better than his rival in an inconclusive general election in July, failed in his bid to form a government last week, falling four seats short of a majority.

Under Spanish rules, Sanchez can in turn try to broker a grand alliance that would bring an end to months of political stalemate in the European Union’s fourth-largest economy. Parliament head Francina Armengol announced the king’s invitation on Tuesday.

Sanchez said he wants to form a government as soon as possible, though he refused to give a date for a vote.

The Socialist is seen as having a better shot at winning, though this will depend on securing the seven seats held by hardline Catalan separatist party Junts per Catalunya. It has demanded an amnesty for hundreds of activists linked to a failed 2017 independence attempt as a precondition for support.

Last week, Junts and rival group Esquerra Republicana passed a resolution in the Catalan assembly offering their backing for a government that traces a pathway toward a referendum.

Sanchez ruled this out but signaled he’s open to an amnesty to put an end to the territorial dispute.

“This political conflict has to be resolved in the political realm,” he said. “Catalans want to turn the page on this situation.”

The power struggle between Junts and Esquerra is a threat to the so-called investiture negotiations as both sides push for more concessions in order to win over the pro-independence vote in Catalonia, where regional elections are due in 2025.

If Sanchez fails to stitch together a majority, a fresh general election will be called for January.

Sanchez needs to balance the demands of separatists with growing discontent on the streets as many Spaniards oppose a mass pardon for officials responsible for fanning a conflict that nearly tore the country apart.

The biggest potential beneficiary of an amnesty is Carles Puigdemont, the head of the Junts, who fled to Belgium after the independence bid. Until recently, Sanchez had called for him to face justice.

Feijoo has accused Sanchez of trampling over the constitution in order to remain in office. His People’s Party organized a rally against an amnesty last month that brought more than 40,000 people out onto the streets of Madrid.

Like Feijoo, Sanchez will face two rounds of voting. The first requires an absolute majority. Failing that, he would need to secure a higher number of votes in favor than against in the second.

If successful, Sanchez would head a minority government that will once again be dependent on Catalan and Basque separatist parties, which will push their regional agendas in exchange for support for annual budgets and other key legislation.

(Updates with comments from Sanchez starting in third paragraph.)

©2023 Bloomberg L.P.