DUBLIN — A surge in support for Sinn Féin in Saturday's election upended Ireland’s political landscape, which will make for difficult coalition negotiations and the prospect of a government unlike any the country has seen before.

The left-wing nationalist party won the popular vote, sweeping away the traditional dominance of Fine Gael (the party of Prime Minister Leo Varadkar) and Fianna Fáil.

But the scale of Sinn Féin's success came as a surprise even to leader Mary Lou McDonald. The party blundered by cutting the number of candidates it fielded — it had just 42 when 80 is needed for a majority in parliament — believing targeting a reduced number of seats would help maximize its vote after lackluster local and European elections in 2019.

That decision meant it cheated itself out of holding the most seats in parliament. In the final count, Sinn Féin had 37 seats, Fianna Fáil 38, and Fine Gael 35. Coalition formation looks politically tricky.

Here are the options:

Sinn Féin with smaller parties

McDonald has already contacted smaller left-wing parties to discuss coalition possibilities.

But the arithmetic is tricky. With the Green Party on 12 seats, Labour six, Solidarity/People Before Profit five, and the Social Democrats six, even if every small party participated, the unwieldy coalition would reach only 66 seats and need the support of independents for the majority of 80 needed.

Fianna Fáil and Sinn Féin

A deal between Fianna Fáil and Sinn Féin has been the bookmakers’ favorite. That's despite McDonald saying she would prefer not to include either of the rival big parties in government, and that both Fianna Fáil and Fine Gael ruled out working with Sinn Féin during the election campaign.

But Fianna Fáil leader Micheál Martin softened his tone as the extent of the support for Sinn Féin became apparent. “I'm a democrat,” Martin said. “I listen to the people.”

The idea is controversial among many Fianna Fáil members and supporters because of Sinn Féin’s past as the voice of the armed republican struggle against British rule in Northern Ireland, the Provisional Irish Republican Army.

But some strands of the party are enthusiastic, or at least willing, to set the past aside given Sinn Féin’s support for the Good Friday Peace Agreement of 1998.

"If that's what the party decides, then I would be amenable to it, and I think it's well known that would have been my view for some considerable time,” said Éamon Ó Cuív, a lawmaker who is the grandson of Fianna Fáil founder Éamon de Valera, adding that Fianna Fáil’s own tradition of republicanism meant there were ideological links with Sinn Féin.

“I think their [Sinn Féin's] ethos is much closer to ours than Fine Gael's. Other people would argue otherwise. But if you look at what they stand for and what we stand for, I think poblachtachas or republicanism is not just about trying to reunite this country, trying to heal divisions within this island,” Ó Cuív said. “It's also about trying to make sure that you've got a society where there's a fair distribution of wealth, where the economy is run for the good of all the people, and where we don't get the ever increasing division between those who have and those who don't have.”

The main hurdle in such talks could be who would get to be Taoiseach, or prime minister. With Sinn Féin winning the popular vote, but Fianna Fáil set to win the most seats, both McDonald and Martin may feel they have a claim to the top job.

"I may well be the next Taoiseach," McDonald told reporters.

There was speculation on Tuesday that the solution could be a “rotating Taoiseach,” with the two leaders taking turns.

McDonald and Martin may try to shore up support by first seeking deals with smaller parties and independent politicians before speaking to each other about a coalition.

They need to: the Sinn Féin surge carried in many small left-wing parties and independents at the expense of Fianna Fáil, leaving the two parties short of the 80 seats needed for a majority. The Greens are in prime position to be courted, as they increased their seats to 12 from two.

Fianna Fáil and Fine Gael

A majority could be formed by Fianna Fáil and Fine Gael plus a smaller party or some independents. Ideologically, the parties are not miles apart: Rather than representing different strands of a left-right political spectrum, they are descended from two sides of Ireland’s civil war in the 1920s. Fine Gael brands itself as the more fiscally responsible party and has pioneered socially progressive reforms. Fianna Fáil has a tradition of more social spending and a conservative streak; it is popular among older voters.

Since 2016, the parties have worked together in a “confidence and supply” arrangement. While officially in opposition, Fianna Fáil facilitated the Varadkar minority government by abstaining or supporting it in crunch votes.

Fine Gael continues to rule out any deal with Sinn Féin, but Health Minister Simon Harris has advocated a deal with Fianna Fáil “in the national interest.”

However, such a move would be risky. After years of working together, support for both parties dropped in the 2020 election compared with 2016.

A majority of voters believe it is “wrong” to rule out going into government with Sinn Féin, according to a survey of 5,300 voters as they left polling stations across Ireland by Ipsos MRBI.

A new election

The parliament — Dáil Éireann — is due to meet on February 20. If no majority can be found to support the nomination of a prime minister, Ireland may face another election.

Both Fine Gael and Fianna Fáil may be prepared to compromise on their red lines to avoid giving Sinn Féin the opportunity to rectify their mistake and contest a new election with more candidates, with the aim of emerging decisively as Ireland’s leading party.