By Stefan J. Bos
Duda was welcomed at his headquarters by a crowd of enthusiastic supporters after exit polls showed him ahead by a tiny margin in the presidential run-off against Warsaw's liberal mayor.
Official results later confirmed that he won with slightly more than half of the ballots cast. But it is Poland's slimmest presidential election victory since the end of its Communist regime in 1989.
Andrzej Duda's re-election came as a disappointment to those seeking to reset relations with the European Union. Under Duda, Poland was condemned by EU leaders over government measures to reduce the independence of the judiciary and media.
Activists also claimed that the pro-traditional family and anti-abortion President discriminated against the gay and transgender community. He called LGBT rights an "ideology" more destructive than communism.
But speaking to reporters, Duda made clear that Sunday's presidential vote showed that democracy is working in his heavily Catholic nation.
"I am very grateful and proud that election turnout has really grown during my presidency," Duda said. "I am thrilled that so many people are participating."
Turnout was 68.2 percent, according to official estimates.
Duda added that democracy in Poland is "becoming increasingly mature". He said: "We are being serious about taking matters into our own hands. To decide who is going to govern in our country and who will represent us internationally."
The 48-year-old President Duda, a friend of U.S. President Donald Trump, is a social conservative allied with the government led by the nationalist Law and Justice (PiS) party.
His rival Trzaskowski, had hoped to win the presidency with the backing of the main opposition Civic Platform party, which ruled the nation from 2007 to 2015.
He had pledged to improve relations with the EU by introducing measures such as supporting local governments and free media. The mayor of Warsaw, a former European legislator, also wanted to prevent what he called "violations of the constitution" and to stop what he described as "the politicizing of independent institutions."
Critics fear that President Duda's second 5-year term will be marked by further controversial reforms to the judiciary and other perceived autocratic policies.
However, opponent Trzaskowski's party made clear it is investigating whether Duda's victory is what people wanted. It expressed concerns about reported voting "irregularities" after the polls closed on Sunday.
In one of the incidents, Poles living abroad were allegedly not receiving voting packages in time to take part in the presidential election. And analysts warn the close result could lead to court challenges.