ROME — Italy’s warring political parties struck a deal late Wednesday to form a new government that shunted aside Matteo Salvini, the hard-right leader who dominated the country’s politics for more than a year and threatened to drastically reorient Italy’s place in Europe.

The sudden turnabout in Italy’s politics just a week after the country’s nationalist-populist coalition collapsed was a relief to the European establishment after 14 months of euroskeptic provocations, anti-migrant crackdowns and flouting of the bloc’s financial rules.

The leaders of the anti-establishment Five Star Movement and the center-left Democratic Party, which is poised to return from the opposition, both said on Wednesday that they had overcome bitter differences and agreed that the outgoing prime minister, Giuseppe Conte, should be prime minister again.

Mr. Conte will meet with President Sergio Mattarella, who is responsible with guiding the country through a political crisis, early Thursday morning, when he is expected to be formally handed the mandate to form a government.