He was immediately condemned by conservative opponents for dragging Spain towards "humiliation".
Although the conservative Popular Party won July elections they were unable to form a majority.
The amnesty deal would give the Socialists the numbers they need.
However, right-wing protesters have taken to the streets in Madrid and other cities in recent days, angered by the prospect of a law granting amnesty to hundreds of Catalan politicians and activists "directly or indirectly" related to a failed bid to secede from Spain in 2017.
Popular Party (PP) figures have accused the acting prime minister of writing a "blank cheque for the independence movement". Madrid regional leader Isabel DÃ­az Ayuso said the Socialists were "selling a nation with centuries of history" with an attack on Spain's rule of law.
Judges and prosecutors associations also expressed "profound concern" about the agreement.
Amid the febrile atmosphere surrounding the deal, a former leader of the PP in Catalonia and founder of far-right Vox was shot in the head and wounded on a street in Madrid. His attacker was said to have fled the scene on a motorbike.
Alejo Vidal-Quadras, 78, had earlier condemned the "infamous pact", warning that it would make Spain a "totalitarian tyranny". However, Spanish reports suggested the attack may have been linked to his work defending Iran's exiled opposition.
Mr Vidal-Quadras was said to be in a stable condition.
Before Thursday's agreement, Pedro SÃ¡nchez had already sealed a deal with one pro-independence party. The Catalan Republican Left (ERC) is in power in Spain's north-eastern region.
His negotiators then clinched an agreement with the more radical Together for Catalonia (JxCat). It is led by Carles Puigdemont, who led the breakaway independence vote but fled to Brussels to avoid being sent to jail.
ERC and JxCat hold seven seats each in the 350-seat parliament.
While Mr Puigdemont went into exile in 2017, nine other Catalan leaders were jailed for sedition before being pardoned by Mr SÃ¡nchez in 2021. The crime of sedition has since been removed from the penal code but Mr Puigdemont is still accused of disobedience and embezzling public funds, and many others have faced similar allegations.
Under the agreement of just over three pages, the draft amnesty covers charges arising from the start of the Catalan push for independence in 2012 to 2023 but it does not refer to any named individuals.
It says JxCat will propose holding a "self-determination referendum on the political future of Catalonia" within the terms of the Spanish constitution while the Socialist party says it will defend the "broad development" of Catalonia's autonomy by judicial means.
The text also refers to "lawfare", a word used by JxCat to refer to judicial cases it claims were used to persecute pro-independence figures politically.
Mr Puigdemont said the deal marked a step towards resolving "the historic conflict between Catalonia and Spain".
Santos CerdÃ¡n, the Socialist party negotiator, said it gave a historic opportunity for tackling what "can and should only be dealt with politically".
"It's necessary to form a progressive government as soon as possible, that gives stability to Spain and that fulfils the mandate of the people in last elections."
The leader of the conservative PP, Alberto NÃºÃ±ez FeijÃ³o, spoke of a day that would go down "in the dark history of our country". Calling for further protests, he said the acting prime minister had formed an alliance for personal convenience and had utterly surrendered to the "blackmail of the independence movement".
Party colleague Isabel DÃ­az Ayuso told Spanish TV that the Socialists had betrayed all their principles. Accusing the acting prime minister of deciding to stay in office despite losing the election, she said his party was guilty of sneaking "a dictatorship through the back door".
Four judicial groups signed a joint statement objecting to the deal's claims of "lawfare" waged against pro-independence activists. They warned against interference in the independence of the judiciary and said expressions reflecting "distrust" were unacceptable.
The controversial amnesty law will be put before parliament in the coming days and, assuming it passes, the next step will be for an investiture debate and a vote around Thursday next week.
The European Commission said it had written to the caretaker government in Spain for information about the draft law. A spokesman said it had been contacted "by a large number of citizens and stakeholders who had concerns about [the amnesty]".
Spain's Socialist acting prime minister, Pedro SÃ¡nchez, has agreed a controversial amnesty deal with a Catalan separatist party, bringing him closer to four more years in office.