The election commission said that Mr Duda had won 51.2 per cent of the vote with results from more than 99.97 per cent of polling stations counted, and that tallying up the final votes would not change the outcome.
It makes Sunday’s election one of the tightest ever in Poland’s history, with the liberal mayor of Warsaw Rafal Trzaskowski narrowly behind Mr Duda on 48.8 per cent of the vote.
The difference in votes between the candidates is thought to be around half a million.
The re-election of Mr Duda will allow PiS to enact more conservative policies, including media and judicial reforms which have previously been deemed undemocratic by the European Union.
“What it means for Poland is that you’ve got a clear three-year run ... when Law and Justice can continue to implement its radical programme of state-reconstruction,” he added.
If Mr Duda had lost the election, Mr Szczerbiak said that the ruling party’s controversial legislative programme would have effectively been “hamstrung” because it lacks the 60 per cent majority needed to overturn a presidential veto.
His comments came after the opposition candidate Mr Trzaskowski said on the campaign trail that, if elected, he would block any legislation that undermined the rule of law.
Jan Zielonka, a professor of European politics at the University of Oxford, said that despite the close result it was a “winner takes it all” election.
He added that only a Democratic victory in the US’s November elections could lead to significant pressure being applied against the Polish government, which has been overtly pro-Trump in recent years.
Referring to the leading politicians of PiS, he added: “They look, walk and talk like Trump – all of them. If the Democrats come to power, there will be a price to pay.”
During a divisive campaign, Mr Duda targeted the country’s LGBT+ community, saying in June that “LGBT ideology” was “more destructive than communist indoctrination”.
The incumbent president also promised to ban marriage for gay couples in his bid for re-election.
This came at the same time as the country’s first openly gay presidential candidate, Robert Biedron, was running for election.
As well as denouncing gay rights, the ruling party also used antisemitic tropes in the run-up to the vote by casting Mr Trzaskowski as someone who would sell out to Jewish interests.
Jaroslaw Kaczynski, the leader of PiS, questioned whether the opposition candidate had a “Polish soul” and a “Polish heart” because he previously said that Poland should discuss compensation for Jewish property seized during the Second World War.
During his campaign, Mr Trzaskowski presented himself as an anti-populist figure, saying he wanted to repair his country’s relationship with Europe.
As the mayor of Warsaw, the liberal candidate signed a declaration of LGBT+ tolerance, which among other things pledged anti-discriminatory sex education in schools and the creation of an LGBT+ community centre in Warsaw.
After the electoral commission announced Mr Duda’s win, Grzegorz Schetyna, the former head of Mr Trzaskowski’s party Civic Platform (PO), suggested that his party would respect the result.
“I don’t want to speak on behalf of the campaign staff, but I think that this difference is large enough that we have to accept the result,” he told private broadcaster TVN24.
The opposition had previously hinted at voting irregularities in Sunday’s election.
Tomasz Siemoniak, a PO member of parliament, told Reuters earlier: “We are gathering information and signals about different irregularities and we are still only talking about polls and only a percentage of results from the National Electoral Commission so we don’t have a full picture of the situation.”
The electoral commission said that the election had seen a near-record turnout of 68 per cent.
Additional reporting from agencies