WARSAW — President Andrzej Duda narrowly won re-election this week, using the same playbook that brought his Law and Justice party to power five years ago: stoking fear and blaming an enemy.
In 2015, it was an enemy at the gates: Migrants, who party leaders said carried “all sorts of parasites,” were threatening the nation.
This time, it was an enemy within: Gay men and lesbians living in Poland, Mr. Duda said, were promoting an ideology “more dangerous than communism.”
Mr. Duda won by a thin margin in the closest election in the country since the end of communist rule in 1989. But the bitter campaign against his opponent, Rafal Trzaskowski, the liberal mayor of Warsaw, exposed old rifts and created new divisions in Poland that are unlikely to go away any time soon.
“This election was focused on inner conflicts and inner division,” said Andrzej Leder, a sociology professor at the Polish Academy of Sciences. “And the level of polarization was stunning.”
The optimism that greeted Mr. Trzaskowski’s campaign has been replaced by despair among his supporters, and those who feel they were targeted by Mr. Duda’s homophobic language fear what may be ahead.
“I am terrified by Duda’s words,” said Kamil Tkaczyk, a 27-year-old hairdresser in Warsaw, who is gay. “Together with my partner we are considering migrating to a country, which would not only be free of prejudice, but most of all, where we could feel safe,” he said.
Mr. Tkaczyk and others who oppose the government say the recent election was not only about trying to safeguard democracy in Poland, where the Law and Justice Party has overhauled the country’s courts in a way that critics say undermines the rule of law.
It was also about defending the country’s place in Europe and the world.
While supporters of the government point to the generous social welfare programs that have helped bridge economic inequality in Poland, many who voted for Mr. Trzaskowski blame Mr. Duda’s campaign for solidifying the political polarization that has taken hold across the country.
“Politics is becoming really brutal again,” said Mr. Leder, the professor. “While the ruling party won politically, they have not won culturally,” he added. “The government knows these are the last years they can really try and change the mentality of the country.”
Party leaders have already signaled they plan to move forward with proposals that would silence critics, apply pressure on academic institutions and exert even more control of the courts. In April, the Court of Justice of the European Union ordered the suspension of a new disciplinary chamber of the Polish Supreme Court, which has a politically selected membership and extraordinary powers to prosecute judges who oppose the government.
Some of the most influential and nonpartisan media outlets in the country are owned by foreign companies, such as Ringier Axel Springer, a German publisher. During the campaign, Mr. Duda warned of a “German attack” in the election and criticized the Warsaw correspondent for the German newspaper Die Welt.
Jaroslaw Kaczynski, the party leader, said on Tuesday that “media in Poland should be Polish.” Mr. Kaczynski also told the Polish Press Agency that the government planned to “take actions” to ensure media outlets covered the news “more realistically.”
Mr. Leder, who opposes the Law and Justice party, said that people under the age of 50 sent a clear message to the ruling party by thoroughly rejecting Mr. Duda and his campaign.
Younger, urban voters overwhelmingly supported Mr. Trzaskowski, whose campaign nearly dislodged an incumbent president with a host of advantages, including the use of state media and the help of prominent supporters within the Catholic clergy as well as President Trump.
Mr. Trzaskowski won Warsaw with 68 percent of the vote. He also won voters aged 40 to 59 by 10 points, those 30 to 39 by 11 points, and those 18 to 29 by nearly 30 points. Mr. Duda handily beat the Warsaw mayor with voters over 50 by nearly 20 points and those over 60 by 25 points. Mr. Duda supporters were also mostly in eastern and southern regions of the country, where the economy is still lagging.
Cezary Tomczyk, the head of Mr. Trzaskowski’s campaign team, said they planned to file a formal protest with the Supreme Court disputing the election results. But few expect the challenge to lead to any action or change the outcome, given the party’s control over the courts.
Jan Grabiec, a spokesman for the opposition Civic Coalition party, said they were also reviewing complaints, especially with regard to ballots cast outside the country, which were handled by the government.
“What happened abroad is an enormous scandal,” said Mr. Grabiec. “Wherever the election was organized by the National Electoral Commission, it went more or less OK. But wherever it was organized by people subject to the government, it was a disaster,” he said.
Marcin Matczak, a constitutional scholar who has opposed the changes to the judiciary made by Law and Justice, said there is now a systemic problem with the courts.
“The key function of the courts is to settle social conflicts in a civilized manner,” he said. “After what Law and Justice did to the judiciary, the Supreme Court that is to issue the decision on the validity of the election cannot fulfill this function anymore.”
Many in the country will not respect the court’s decision, no matter how it rules.
The conflict “over the fairness of the presidential election will go on instead of being settled by the Supreme Court,” said Mr. Matczak. “The bad emotions will escalate, the divisions will grow. This is what happens to a society deprived of an independent judiciary.”
Since declaring victory, Mr. Duda has struck a conciliatory tone. “It was a tough campaign, at times probably too tough,” he said on Monday. “If anyone felt offended by my words, I ask them to forgive me. And to give me another five years to improve.”
His assurances are unlikely to satisfy Zbigniew Maraszek, a 53-year-old high school teacher from Plonsk, a city of 20,000 in central Poland. Mr. Maraszek said the government had created an atmosphere that had become “unbearable.” His wife, Katarzyna, a 47-year old university teacher, blamed the government for “weaponizing” the Catholic Church in the party’s fight against homosexuality.
“I consider myself a Catholic, but I find it unacceptable,” she said.
Still, despite her strong support for Mr. Trzaskowski, Ms. Maraszek was not able to convince her mother to change her mind at the polls.
Her mother, she said, voted for Mr. Duda.
Monika Pronczuk and Anatol Magdziarz contributed reporting.