By Joanna Plucinska and Alicja Ptak
WARSAW, July 12 (Reuters) - Incumbent Andrzej Duda was marginally ahead in Poland's presidential election on Sunday, an exit poll found, in a result seen as likely to have profound implications for Warsaw's relations with the rest of the European Union.
The re-election of Duda, an ally of the ruling nationalists Law and Justice (PiS), is crucial if the government is to implement in full its conservative agenda, including judicial reforms that the European Union says are undemocratic.
Duda's challenger, liberal Warsaw Mayor Rafal Trzaskowski, has pledged to repair Poland's relations with Europe and use the presidential veto power to hold back any legislation that would subvert the rule of law.
The exit poll by Ipsos showed Duda winning 50.4% of the vote, while Trzaskowski, the preferred candidate of the main opposition party, the centrist Civic Platform (PO), had 49.6%. Ipsos said it was too early to call a winner.
"All we need is to count the votes. The night will be tense but I am certain that when the votes are counted, we will win," Trzaskowski told supporters in a park just outside Warsaw's historic Old Town.
Partial official results are expected on Monday.
Opinion polls before the election had shown the candidates, both 48, neck and neck, with Trzaskowski having closed the gap on Duda, who initially looked like a clear favourite.
Backed by the government, Duda ran an acrimonious campaign, laced with homophobic language, attacks on independent media and accusations levied against Trzaskowski that he would serve foreign interests instead of Poland's.
Duda, a devout believer, had painted himself as a defender of Catholic values and of the government's generous social benefit programmes that have transformed life for many, especially in the poorer rural regions of the country.
He appeared conciliatory on Sunday. "If anyone was offended by anything I did or said in the last five years, not just during the campaign, please accept my apology," he told supporters in Pultusk, a small town north of the capital.
Duda has also championed large infrastructure projects, which he says will create jobs and boost the country's autonomy and international standing.
For many religious conservatives in Poland, Trzaskowski came to represent the threats facing traditional values when he pledged to introduce education about LGBT rights in the city's schools.
The archbishop of Krakow, Marek Jedraszewski, told worshippers in the southern city of Czestochowa on Saturday that Poland faced a "lethal danger" from ideologies that seek to undermine the traditional family structure and corrupt children.
Trzaskowski says he seeks a more tolerant Poland and has criticised PiS' rhetoric, vowing to abolish state news channel TVP Info, which critics say gave overt support to Duda in its programming.
"In politics, you should have opponents, not enemies," Trzaskowski said on Sunday. "They thought they had full power, but today they have fear in their eyes."
Duda' re-election to a second five-year term would open up the prospect of three years of uninterrupted rule by PiS, which controls the lower house of parliament, with the next national election scheduled for 2023.
Observers say his defeat could undermine the fragile parliamentary majority that supports the PiS government, raising the spectre of political instability as Poland is coping with the economic fallout from the coronavirus pandemic.
The election is being closely watched in Brussels.
Before PiS and Duda came to power in 2015, Poland had one of the most pro-European administrations in the bloc's ex-communist east. But it has grown increasingly isolated, with divisions focusing on climate change and migration, in addition to democratic norms.
(Reporting by Joanna Plucinska and Alicja Ptak; Additional reporting by Alan Charlish, Pawel Florkiewicz, Marcin Goclowski and Anna Koper; Writing by Alan Charlish and Justyna Pawlak; Editing by Frances Kerry, Louise Heavens and Peter Cooney)
Our Standards: The Thomson Reuters Trust Principles.