This article is more than
4 year oldThe National Electoral Commission said Mr Duda had won 51.2% of the votes.
It is Poland's slimmest presidential election victory since the end of communism in 1989.
One of the major issues of the election was the future of the country's strained relations with the European Union.
Mr Duda is a social conservative allied with the government led by the nationalist Law and Justice (PiS) party, while Mr Trzaskowski is the socially liberal mayor of Warsaw.
Mr Duda's win is expected to lead to further controversial reforms to the judiciary and continued opposition to abortion and gay rights.
During the campaign Mr Duda came under heavy criticism after he said LGBT rights were an "ideology" more destructive than communism.
At a press conference on Monday morning, the heads of the electoral commission said they were not sure when complete results would be announced, as some polling stations had yet to submit their counts.
But with 99% of all constituencies reporting, those tallies were not expected to affect the result. Turnout was reportedly 68.2%.
The opposition Civic Platform (PO) group - which backed Mr Trzaskowski - told Reuters news agency it was collecting information on voting "irregularities" after the polls closed on Sunday, including reports of Poles abroad not receiving their voting packages in time to take part in the election.
Analysts believe the close result could lead to court challenges.
"I think there will certainly be electoral protests and I think the whole issue will end up in the Supreme Court," Warsaw University political scientist Anna Materska-Sosnowska told AFP news agency.
The election had been due to take place in May, when Mr Duda was higher in the polls and stood a better chance of winning in the first round.
Although the coronavirus pandemic had not yet peaked, the government was desperate for the May vote to go ahead.
It eventually backed down when a junior coalition partner joined the opposition in saying the Law and Justice party was putting politics before public health.
President Duda's victory means the governing Law and Justice party can now implement its programme unhindered until the next parliamentary elections in three years.
The presidential election was the closest since the fall of communism in 1989 but the high turnout means President Duda won a clear mandate.
Despite the economic impact of the coronavirus pandemic, the government has pledged to continue its popular welfare scheme that has helped raise many Polish families out of poverty.
More controversially, Law and Justice has said it wants to complete its overhaul of the judiciary - a policy criticised by the EU and many other international organisations for undermining the rule of law in Poland. That signals more tension with Brussels.
Law and Justice may want to use Mr Duda's victory to pursue greater political control of local government and the private media.
But passing legislation to limit foreign ownership of critical private media is difficult under EU rules and risks antagonising Poland's chief ally, the US, as one of the country's most popular broadcasters, TVN, is owned by an American company.
Mr Duda's victory shows there is a strong electorate for social conservatism and generous state hand outs. But the closeness of the vote also suggests that many in Poland are uneasy about the government's attempts to introduce a more illiberal democracy.
Newer articles
<p>The two leaders have discussed the Ukraine conflict, with the German chancellor calling on Moscow to hold peace talks with Kiev</p>