The re-election of Duda, an ally of the ruling Law and Justice (PiS) party, is crucial if the government is to implement in full its conservative agenda.
“I want to thank everyone that voted for me, also the critics,” Duda told supporters after the exit poll was announced.
Duda got 50.4 percent of the vote, the exit poll showed, while Rafal Trzaskowski, the liberal mayor of Warsaw and preferred candidate of the main opposition party, the Civic Platform (PO) had 49.6 percent.
The exit poll has a margin of error of two percentage points for each candidate, pollster Ipsos said.
Partial official results are expected on Monday.
Opinion polls before the election had shown the candidates neck and neck, with Trzaskowski having closed the gap on Duda who had initially looked like a clear favorite.
During an acrimonious campaign, Duda had painted himself as a defender of Catholic values and of the government’s generous social benefit programs that have transformed life for many, especially in the poorer rural regions of the country, the EU’s largest post-communist member.
He also championed large infrastructure projects which he says will create jobs and boost the country’s autonomy and international standing.
While Poland’s president has limited executive power, Trzaskowski has pledged to use the presidential veto if he wins to stop any further court reforms.
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.
By Anna Koper and Marcin Goclowski