Spanish Acting Prime Minister Pedro Sanchez looks set to clinch another term in office after his Socialist Party secured the backing of Catalan separatist party Junts to form a government in a deal the country's opposition condemned as "a humiliation".
A law granting amnesty to those prosecuted over Catalonia's attempt to secede from Spain was included in the deal, the text showed.
Santos Cerdan, a senior Socialist official, told a media conference in Brussels that, while his party still had "profound disagreements" with Junts, it had put them aside in the interests of forming a "stable government".
The agreement included Junts lending its votes in parliament to support legislation for a full four-year term, he said.
But Junts, which seeks another independence referendum for the wealthy northeastern region, said supporting each law would depend on talks involving Catalonia's political conflict.
Debating and voting on the investiture will take place on November 15 and 16.
Sanchez's conservative opponents have accused him of putting the rule of law in Spain on the line for his own political gain.
As a deal between Junts and the Socialists edged nearer in the past week, the mood in the country has become increasingly febrile, with protesters clashing with police outside the Socialists' headquarters in Madrid.
Fireworks and other objects were thrown at police on Thursday as thousands of protesters demonstrated outside the Socialists' headquarters in Madrid.
Banners reading "Sanchez traitor" were held aloft by the demonstrators on the seventh night of protests in the Spanish capital.
Santiago Abascal, leader of the far-right Vox party who attended the protest, told reporters: "We are facing the end of democracy, the biggest attack on national unity ever."
Other protests took place in Barcelona and Valencia.
An amnesty could exculpate as many as 1400 activists and politicians involved in the attempt to separate Catalonia from Spain.
Among the beneficiaries is Carles Puigdemont, the Junts leader living in exile in Belgium because of charges he faces as Catalonia's leader during the separatist drive in 2017.
If the amnesty is approved by congress, the 60-year-old would be able to return to Spain and potentially run for office.
Puigdemont hailed the agreement as a "change of narrative" and a step towards resolving a "historic conflict" between Spain and Catalonia.
He told reporters in Brussels that Catalans did not need to recognise they had committed any crime nor apologise, something the Socialists had originally insisted on in negotiations.
Sanchez is trying to form a government after a July election produced no outright winner.
He reached a deal to govern in coalition with the hard-left Sumar grouping last month but also needs several other smaller parties.
Even with Junts' support, the Socialists would still fall short of a majority in the 350-seat congress.
They still need the support of five MPs from the Basque Nationalist Party. which has yet to confirm its support.
The vote has to be concluded by November 27 or a fresh election is triggered.