The leaders of Italy’s centre-left Democratic Party (PD) and populist Five Star Movement say they have agreed to form a coalition government.
“We consider it worthwhile to try this experience,” the PD’s Nicola Zingaretti said after meeting the president on Wednesday – the deadline for any deal.
It was agreed that Giuseppe Conte should stay on as prime minister.
The planned joint administration will serve until the next scheduled elections in 2023.
On Tuesday, Five Star leader Luigi Di Maio welcomed what he referred to as the PD’s willingness to accept Mr Conte’s reappointment.
The two parties, traditionally staunch rivals, have been holding tense talks following the collapse of the previous coalition government last week.
“In difficult times like these, shunning our responsibility to have the courage to try this is something we cannot afford,” Mr Zingaretti said.
His comments came after President Sergio Mattarella met party leaders in Rome to try to chart a way forward. The president is due to make a statement on the outcome of the talks later on Wednesday.
If an agreement had not been reached, he would have named a caretaker government and called early elections.
How did we get here?
The two parties have been in discussions since Mr Conte resigned as prime minister in dramatic fashion last week.
His decision came after Matteo Salvini, the leader of the nationalist League party, tabled a no-confidence motion against him.
During his 20 August resignation speech, Mr Conte launched a blistering attack on Mr Salvini, accusing him of being “irresponsible”.
Mr Salvini’s League party had been in power with the anti-establishment Five Star Movement for 14 months when he effectively ended the coalition, saying he could no longer work with his partners.
The potential new coalition represents a major setback for Mr Salvini as he hoped to win outright power in a snap election, the BBC’s James Reynolds says.
Both Mr Salvini and Forza Italia leader Silvio Berlusconi called for fresh elections after meeting President Mattarella.
Why had Salvini had enough?
Following weeks of hostility between the two ruling parties, Mr Salvini called for a snap election this month, saying that differences with his Five Star coalition partners could not be mended.
A failed attempt by Five Star to scrap plans for a high-speed rail link showed that the coalition could no longer govern, the right wing leader said at the time.
However, addressing the Senate last week, Mr Conte said that Mr Salvini had been “looking for a pretext to return to the polls” since his party’s success in European elections in May.
The League has soared ahead of Five Star in opinion polls, due mainly to Mr Salvini’s stance against illegal immigration, but has fallen back slightly since pulling the plug on the coalition.
In the May elections, the League came top with 34% of the votes in Italy, whereas Five Star got about 17%.
Despite this, Mr Di Maio has said his party does not fear another election.