Talks between the leaders of Italy’s Democratic party (PD) and the anti-establishment Five Star Movement (M5S) went on late into the night on Monday as they sought to thrash out an agreement on a potential alliance that could avert a snap election.

Giuseppe Conte, the outgoing prime minister, joined the meeting between the PD leader, Nicola Zingaretti, and his M5S counterpart, Luigi Di Maio, in a sign that Zingaretti has succumbed to M5S’s demands to reinstate Conte.

The nomination of Conte, who last week ended an ill-fated coalition government between M5S and the far-right League, has been the main obstacle in the talks.

“It’s close, but not set in stone,” a source close to the discussions said before the meeting. “If Conte is nominated prime minister, then it could be in exchange for M5S losing some ministries to the PD.” Di Maio might also be forced to step down as deputy prime minister in exchange, the source added.

Zingaretti declined to respond to questions about Conte’s potential return after an initial meeting with Di Maio in Rome on Monday evening, but said: “We are on the right track. I’m optimistic about making this agreement. Creating a government is a serious thing – we are serious people – and we don’t want [a government] that finishes after 14 months like the M5S-League one.”

The PD leader, who until last week was reluctant to negotiate with M5S, a longstanding foe, told reporters earlier that Italy needed a “turning point” government that required a break from the past.

The president, Sergio Mattarella, is expecting to see serious signs of progress towards the creation of a new parliamentary majority before beginning fresh consultations with the leaders of Italy’s main parties from Tuesday afternoon. Zingaretti and Di Maio are due to meet Mattarella separately on Wednesday. If a viable deal is struck, Mattarella could give them more time to formalise a plan. If the talks implode, he will probably install a caretaker government until new elections.

Zingaretti has been under pressure from his PD colleagues and supporters to accept Conte as a possible prime minister. “I think it’s absurd to fight over Conte, he is a decent person who has shown great courage … we have a great opportunity,” wrote one on Zingaretti’s Facebook page. “Why veto Conte?” asked another. “This agreement should have been done over a year ago.”

A Twitter campaign to reinstate Conte was launched after his blistering attack in the senate last week against Matteo Salvini, who dramatically withdrew his League party from the alliance with M5S this month as he sought to exploit his high popularity to force snap elections and become the next prime minister.

Salvini’s moves have cost the party support: the League has slipped to 33.7% from 38.9% in late July, according to a poll published on Sunday. He had not banked on the possible M5S-PD tie-up or that Conte could emerge as his main rival. Conte eclipses both Salvini and Di Maio in the popularity stakes, commanding 61%, according to a survey on Saturday.

Salvini has made peace overtures to M5S to restore the government. Italian media reported that Salvini and Di Maio were due to meet on Monday, although spokespeople did not respond to a request for confirmation. The chances of them reviving the partnership are remote but cannot be completely ruled out.