It boiled down to a choice between two different visions of the future: one dominated by nationalism, traditional Catholic norms and the defense of Polish sovereignty; the other by promises to “bring Poland back to Europe” and the liberal democratic values espoused by the European Union.
In the end, after a long, vicious election campaign in a highly polarized country, opponents of the nationalist governing party, Law and Justice, won a clear majority of seats in a pivotal general election held on Sunday, according to final official results Tuesday.
That victory opened the way for a potentially drastic shift away from Poland’s deeply conservative policies at home and its role abroad as a beacon for right-wing groups and politicians opposed to liberal values.
The European Union has long clashed with Poland’s government over the rule of law, the protection of minority rights and other issues. Now a new government in Warsaw offers an opportunity for a reset with the most populous and, in terms of economic and military power, most important of the formerly communist states admitted after the end of the Cold War.
At a time when the bloc is reeling from the strains of the war in Ukraine and issues like immigration, Poland matters more than ever.
The prospect of an end to years of testy relations between Warsaw and Brussels has delighted Polish liberals and those elsewhere worried by what had, for a time, seemed like a rising tide of right-wing, and sometimes left-wing, populism in Poland and across Europe.
But “a tsunami of populism turned out to be not so popular,” said Jaroslaw Kuisz, the author of a recent book, “The New Politics of Poland.”
The glee of Polish liberals was tempered by awareness of how difficult it will be to change Poland’s course after eight years of rule by Law and Justice.
“We are waking up from a bad dream, but this dream took place and will be hard to get over,” Mr. Kuisz said. Law and Justice, he added, has “mined the system and laid many traps” in the judiciary and elsewhere that will slow or block a change of course.
For Slawomir Debski, director of the Polish Institute of International Affairs, a state-funded body, the election campaign, dominated by insults and promises of quick fixes, showed that populism is not a monopoly held by one side and is unlikely to go away.
All parties campaigned on simplistic messages, broadcast on social media, he said.
“Sophisticated arguments simply don’t fly,” Mr. Debski said. “What I see, unfortunately, is a global trend introducing populist arguments to any political debate by all sides. We are all influenced by the TikTok invasion of politics.”
The election, cast by both sides of the political divide as Poland’s most consequential vote since voters rejected communism in 1989, offered a multitude of parties from the far right to the progressive left. Enthusiasm ran so high that more than 74 percent of the electorate voted, higher than the 62 percent who turned out for the 1989 poll.
“These are absolutely historic moments,” Donald Tusk, leader of the main opposition party, Civic Coalition, told euphoric supporters in Warsaw as official results were announced Tuesday. “The weather has changed,” he added before repeating a line from a popular song often used during his party’s campaign: “It’s time for a happy Poland.”
Held just two weeks after voters in neighboring Slovakia handed victory to a Russia-friendly party tainted by corruption, the Polish election was closely watched as a gauge of Europe’s direction.
It was also seen as a measure of whether Hungary, increasingly authoritarian under Prime Minister Viktor Orban, would remain an idiosyncratic outlier or become the standard-bearer of a growing cause whose friends extend beyond ideological allies like the TV personality Tucker Carlson, a big fan of Mr. Orban, to include European governments.
Hungary and Poland for a time were close partners, leading what they promoted as a “European renaissance” rooted in Christian values and national sovereignty, but they parted ways over the war in Ukraine. Mr. Orban tilted toward Moscow while Poland offered robust support for Ukraine, though that position wobbled somewhat during the election campaign.
Mr. Debski predicted that Poland and Ukraine would now try to calm ill-tempered quarrels that blew up in weeks leading to Sunday’s election, particularly over Ukrainian grain. Law and Justice banned the import of the grain in an effort to calm angry Polish farmers, an important bloc of voters.
But, Mr. Debski added, “what happened during the campaign had its reasons: public sentiment has been shifting” away from unconditional support.
The results of the election have cast gloom over Law and Justice, which had campaigned on promises to save Poland from European bureaucrats pushing “L.G.B.T. ideology” and what it denounced as Germany’s hegemonic aspirations.
A final tally of votes released on Tuesday by the electoral commission gave Civic Coalition, and two smaller groups also opposed to the Law and Justice party — Third Way and New Left — 248 seats in the 460-member Sejm, the more powerful lower house of Parliament.
Together they won 53.7 percent of the vote, compared with 35.4 percent of ballots cast for Law and Justice. That tally reduced Law and Justice’s presence in the Sejm by 33 seats.
Arkadiusz Mularczyk, a prominent Law and Justice legislator, acknowledged defeat, saying that “we cannot be offended by democracy” and that, “after eight difficult years in government, perhaps it is time for the opposition.”
He conceded that his party’s campaign, focused on vilifying Mr. Tusk, illegal immigrants and the European Union, was at times “too harsh.”
Poland remains deeply divided by generation and geography, with Law and Justice sweeping less prosperous rural areas in the south and east, while Civic Coalition strengthened its grip on urban centers like Warsaw and richer regions in the center and west.
But, reversing a trend across Europe toward increased youth disenchantment with electoral politics of all ideological shades, Poles under 29 voted in larger numbers than voters over 60. That was despite the two main rival camps being led by veterans — Jaroslaw Kaczynski, 74, the Law and Justice chairman, and Mr. Tusk, 66, the leader of Civic Coalition, both former prime ministers.
The opposition also won a large majority of seats in the 100-member Senate, the upper house, but its victory in both chambers of Poland’s Parliament, though a big symbolic boost for supporters of liberal democracy and European integration, will be crimped by its having to work with a Polish president loyal to Law and Justice.
The president, Andrzej Duda, an outspoken critic of Mr. Tusk in the past, will stay in office until elections in 2025 and, until then, can veto legislation passed by his political opponents in Parliament. Mr. Duda is now responsible for asking someone to form a government, a task that will probably fall, at least initially, to a member of Parliament from Law and Justice, which won more votes than any other single party.
Without a majority, Law and Justice is unlikely to succeed and Mr. Duda will need to turn to the opposition.
With Parliament and the presidency held by rival camps, Poland could face a protracted period of political stalemate, a risk heightened by the fact Law and Justice loyalists are deeply entrenched in the judiciary, the national prosecutor’s office and many other state bodies and will be difficult to dislodge without recourse to legally dubious methods.
“The fall of an authoritarian regime is always an extremely dangerous process,” Maciej Kisilowski, a professor of law and strategy at the Central European University in Vienna, wrote in a commentary for the liberal newspaper Gazeta Wyborcza.
Law and Justice clashed so repeatedly with the European bloc that some questioned whether Poland might be forced to follow Britain and exit the union. However, that is a scenario that the governing party always insisted it did not want and dismissed as opposition scaremongering.
A large majority of Poles, according to opinion polls, want to stay in the European Union, a sign that not only urban liberals support the bloc but so, too, do many conservative rural voters who are aligned with Law and Justice on cultural issues but reluctant to lose billions of dollars in funding from Brussels.
A change in government, said Mr. Kuisz should help dilute the bad blood between Warsaw and Brussels, particularly as Mr. Tusk, who could be Poland’s new prime minister, served for three years as president of the European Council, the bloc’s main power center. But, the author cautioned, “putting Poland back in Europe will be not so easy.”
Anatol Magdziarz contributed reporting.