ROME — Italy’s two upstart populist political parties were pushing Thursday to form a government that would combine elements of euro-skepticism and far-right protectionism and place Italy at the forefront of this continent’s rebellion against the old political order.

The talks between the Five Star Movement and the League, the parties most buoyed by Italy’s election in March, marked a sudden development after two months of political deadlock. But hurdles remain, and the two parties could still need days to sort through their issues — including the selection of a new prime minister.

If a deal can be reached, it would make Italy the first core Western European country to form a fully populist government — one that, in this case, wants to draw closer to Russia, take a far tougher stand against migrants and fight back against some of the European Union’s budget restrictions. Such a government would also test how well an insurgent class of politicians could run a country that is struggling with two decades of economic stagnation and an influx of migrants.

“Now we’ll move forward as soon as possible to give a government to Italy,” Luigi Di Maio, leader of the Five Star Movement, said Thursday after talks with League leader Matteo Salvini. “These are very important moments for the Italian Republic.”

The two parties, though separated by some policy differences, have both made their names in defiance of the establishment. The League, until a recent rebrand, was a party that opposed the very idea of a unified Italy, calling for the secession of the country’s more prosperous northern region. Salvini widened the party’s national appeal by turning his ire away from residents in the south and toward migrants and bureaucrats in Brussels. He now pledges to deport 600,000 migrants. He has called for the closure of mosques and says that economic sanctions against Russia are “madness.” He has often criticized the euro, calling it a “German currency.”

The Five Star Movement, meantime, is less a far-right party than an unconventional one. It was founded by a comedian and positioned itself as a tech-savvy vanguard for a new version of anti-elitist democracy. Its leaders have vowed to put major decisions to an online polling of party members. Five Star draws support from both the left and right. Di Maio, 31, has questioned European integration but more recently backed away from that stance. Five Star’s platform is loaded with bread-and-butter domestic spending policies — including providing generous benefits to low-income workers and the unemployed — that could put it in conflict with the European Union.

“These are the gatekeepers of a new political system in Italy,” said Massimiliano Panarari, who teaches political communication at LUISS Guido Carli, a university in Rome. “They are similar in general ideology: They are both nationalist, they are both anti-European — in the sense that they would defend Italian interests against the European Union. I think on these points there is basis for an arrangement.”

Interviewed Thursday evening on the political talk show “Piazzapulita,” Alfonso Bonafede, a top Five Star member, said talks between his party and the League were going “very well” and raised the possibility that the prime minister they select might be a member of neither party.

Italy has been in political paralysis since an inconclusive March 4 election in which no party won a large enough share of the vote to form a government. The Five Star Movement earned 33 percent of the vote; the League and its coalition partners — Forza Italia and two much smaller parties — claimed 37 percent.

Both Di Maio and Salvini felt they deserved to become prime minister. But neither, in weeks of negotiations, could strike a deal to form a majority in the Parliament. Five Star officials said the sticking point was Silvio Berlusconi, founder of Forza Italia, who as a longtime and scandal-prone prime minister squarely represented Italy’s political establishment.

The parties were pushed to deal with one another this week after President Sergio Mattarella, who plays a referee-like role in post-election negotiations, threatened to establish a “neutral government” of technocrats that could lead Italy until its next election. On Wednesday, Berlusconi signaled his willingness to back away and allow a Five Star-League tie-up. That move would leave Berlusconi’s party outside of government.

“This ultimatum put everybody in front of the abyss, with the clarity of mind of somebody who is about to be hanged,” said Franco Pavoncello, the president of John Cabot University in Rome. “Everybody came to their sense.”

“Did it cost him politically? The answer is yes,” said Giorgio Mulè, the Forza Italia spokesman in Parliament. He said Forza Italia would continue to support policies that matched its center-right platform.

Although the March election didn’t immediately lead to a new government, it registered as a signal of anger in a country where the economy remains nearly the size it was two decades ago and where people speak routinely about the combination of high taxes and unreliable public services.

Italy also has shouldered a disproportionate amount of the burden of Europe’s migrant crisis: More than half a million migrants have arrived in Italy over the past five years. Most have been unable to move farther north to other European countries, and the E.U. has failed to work out a deal that would disperse migrants more evenly across member nations.

Italy and other Mediterranean countries “cannot become the refugee camp of Europe,” the Five Star Movement says in a statement of campaign positions posted on its official website.

The spread of anti-establishment populism has also spread to Greece, another country with a beleaguered economy that has dealt disproportionately with the migrant crisis.

But Italians are not fully committed to an anti-E.U. stance. Mattarella gave a speech Thursday in Florence in which he warned against “sovereigntist story­telling,” saying that nationalism wasn’t a solution to modern problems.

Some analysts said that a potential Five Star-League government could also be hindered in fulfilling campaign promises by its relative youth and inexperience.

“We’re not talking about massive policy changes necessarily, because the truth is they’ll be unable to deliver on them,” said Nathalie Tocci, director of the Italian International Affairs Institute. “To go for the big rupture requires delivery. We’re talking about people who have never held government positions.”