Poland's state electoral commission said that conservative President Andrzej Duda has won 51.21% of the vote with almost all votes counted in the country's weekend election.
The nearly complete results, based on a count of votes from 99.97% districts, shows liberal Warsaw Mayor Rafal Trzaskowski just behind with 48.79% of the vote.
The final results could vary somewhat, however.If the result is born out, it would be one of closest elections in Poland's history, reflecting the deep divisions in this European Union nation. Sunday's vote was originally planned for May but was delayed amid bitter political wrangling.
It follows a bitter campaign dominated by issues of culture in which the government, state media and the influential Catholic church all mobilized in support of Duda, a social conservative.
Duda, who is backed by the ruling right-wing Law and Justice party, campaigned on traditional values and social spending in this mostly Catholic nation as he sought a second five-year term.