The leaders of Italy's centre-left Democratic Party (PD) and populist Five Star Movement 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.
President Sergio Mattarella, who met party leaders in Rome to try to chart a way forward, has summoned Mr Conte to a meeting on Thursday morning.
He is widely expected to give him a mandate to form a new government.
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.
Both Mr Salvini and Forza Italia leader Silvio Berlusconi called for fresh elections after meeting President Mattarella.
A major blow for Salvini
This coalition agreement represents a major setback for the League's leader Matteo Salvini.
For 14 months, he was the dominant figure in Italian politics. But a share of power wasn't enough for him - he wanted outright power.
This led him to overreach. Mr Salvini brought down the government last week in the hope of winning a potential snap election.
But it turns out that his gamble had a fatal flaw. The League Party's leader did not count on the possibility of his opponents teaming up to stop him.
A common aim - Stop Salvini - now binds together the Five Star Movement and the Democratic Party in their new coalition. But in order for this administration to last, the two parties may need to find more common ground than their mutual distrust of a single man.
Their coalition will be harried and chased at every step by the man they've sent into sudden opposition.
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.