Spain's Prime Minister Pedro Sanchez has clinched a controversial deal to remain in power by offering amnesty to Catalan separatists, raising tensions across the country.
The accord is aimed at "giving stability to the four-year legislature," Spanish Socialist Party (PSOE) official Santos Cerdan told a news conference in Brussels after negotiations with Catalan separatist leader Carles Puigdemont, who is based there.
Mr Sanchez's PSOE finished second in the 23 July parliamentary elections.
After the first-place centre-right Popular Party (PP) failed to form a government, Mr Sanchez was given until 27 November to gather together a working coalition, or face fresh elections.
He needs the support of Catalan independence parties, and has accepted their demands to offer amnesty to all those being pursued for their role in a failed secession attempt in 2017.
The accord also calls for opening negotiations on the question of "recognising Catalonia as a nation."
Mr Puigdemont hailed the agreement as a "new step" that will contribute a "resolution of the political conflict in Catalonia."
However, he warned that the new coalition will only last if the accord is respected and the negotiations produce results.
Mr Sanchez had already secured the backing of more moderate Catalan separatist parties - as well as far-left and Basque parties - but only now has he nailed down the support of Mr Puigdemont's more radical Junts per Catalunya, or JxCat.
The amnesty law would cover events back to 2012, Mr Cerdan said.
It needs to be approved by parliament to take effect, though eventually would allow Mr Puigdemont to return.

Mr Puigdemont is based in Brussels, having left Spain for Belgium following the failed secession bid to avoid prosecution.
In recent days, conservative opposition parties and members of Spain's judiciary have stepped up criticism of the amnesty plan, with some accusing Mr Sanchez of corruption and abandoning the rule of law.
The proposed bill has sparked several days of tense protests in the country, with 7,000 rallying against it in the capital Madrid on Tuesday, according to authorities.
Protesters in Madrid carried placards with the words "No to amnesty" and "Spain does not pay traitors".
On Monday evening, several thousand demonstrators gathered outside the headquarters of the Spanish Socialist Workers' Party in Madrid, Barcelona and Valencia.
On Saturday, Alberto Nunez Feijoo, head of the PP, said at a meeting that "exchanging votes for impunity is corruption" and vowed at a rally in Valencia a day later: "We will defend Spain."
The opposition accuses Mr Sanchez, who once opposed an amnesty, to be willing to do anything to stay in power.
He has remained defiant in the face of the demonstrations.
On Monday, in a social media message, he criticised "harassment" by the protesters and said their behaviour was akin to "attacking democracy".
Majority of judges have concerns over amnesty
Members of the judiciary have also stepped up their criticism.
The Professional Association of Magistrates, a conservative body that represents the majority of the country's judges, last week issued a statement calling the measures "the beginning of the end of democracy" that would "destroy the rule of law".
After the failed Catalan secession attempt in 2017, hundreds of people were pursued by Spanish prosecutors, sparking claims of repression.
The main leaders of the movement fled abroad, including Mr Puigdemont, or were given jail sentences of up to 13 years.
Mr Sanchez was elected to power just a month after the secession attempt, with the support of separatists.
He has made reducing tensions in Catalonia a priority.
In 2021, he pardoned the nine jailed separatists and the following year his government reformed the Spanish legal code to remove the crime of sedition, under which they had been convicted.
Right-wing Spanish politician shot
A former leader of Spain's main right-wing political party in Catalonia - who went on to co-found the far-right Vox party - has been shot in the head in Madrid, according to a police source.
Alejo Vidal-Quadras "was shot in the head around 1.30 pm (12.30pm Irish time) on Nunez de Balboa Street in Madrid," the source said.
"He was conscious and taken to hospital," they said adding that the National Police homicide unit was leading the investigation.

Emergency services in the Spanish capital said on social media that they were working to "stabilise a 78-year-old male injured with a firearm ... in the area of his jaw".
Mr Vidal-Quadras was leader of the conservative PP party in the Catalonia region in the 1990s.
He went on to become an MEP and was among the founders of the far-right Vox party which he left shortly after its creation.