(Bloomberg) -- Spanish Prime Minister Pedro Sanchez is on the brink of a deal with a Catalan separatist party that will unlock a third term in office for the Socialist leader, according to a person familiar with the matter.

The agreement with Junts per Catalunya may be announced as early as Thursday, with a confidence vote in parliament likely to follow next week, said the person, who asked not to be named discussing confidential negotiations. To be sure, the parties had been in similar situations at least twice in the past two weeks only to see the deal fall through at the last minute.

A spokesperson for the Socialist party didn’t immediately respond to a request for comment. A representative of Junts declined to comment.

The pact would mean Junts supports Sanchez in return for a sweeping amnesty law that would benefit hundreds of Catalan activists who faced charges as part of the fallout from the illegal independence referendum of 2017. The legislation is still being drafted and needs to be ready before the confidence vote can take place.

With the support of seven lawmakers from Junts, Sanchez would be ready to win a confidence vote with the backing of 178 lawmakers in the 350-member parliament in Madrid. Still, a vote will only be held once the amnesty law is agreed on and a bill is registered in parliament, which needs to be done before Nov. 27 or fresh elections will be called.

The deal would open a complicated new chapter in Spanish politics with the 51-year-old premier reliant on a patchwork alliance of seven different parties to pass legislation and confronted by an angry opposition comprising the conservative People’s Party and the far-right group Vox.

Both are vehemently opposed to the amnesty, which would allow former Catalan President Carles Puigdemont to return to Spain six years after he tried to split the country. The PP won the most seats in July’s election but was unable to stitch together a governing coalition in a legislature still bitterly divided by the Catalan issue.

After years on the fringes of national politics and with Puigdemont living in self-imposed exile in Belgium, Junts was handed a chance to reshape the agenda when Sanchez and his more regular partners were left a handful of votes short of a majority.

Puigdemont has personally led the talks with the Socialists from Brussels, dealing with a high-ranking party official from Sanchez’s party and a minister.

For Sanchez the deal would represent another feat of political escapology. 

He’s had to win the leadership of his party twice after being ousted by an internal revolt the first time around. He then seized power through the first successful no-confidence vote since Spain returned to democracy in 1978. He claimed his second term term in 2020 with a minority of 167 votes after 18 lawmakers abstained.

After his party was punished by voters in May’s local elections that appeared to signal the PP was set to return to power, Sanchez called a snap election and managed to deny the two right-wing parties a majority, paving the way for the pact with Junts.

(Updates with party comments, background starting in third paragraph)

©2023 Bloomberg L.P.