Former interior minister Mariusz Kaminski and his deputy Maciej Wasik were released after 9 p.m. local time.

They were jailed this month after being sentenced for abuse of power in their previous roles. Both men went on hunger strike, claiming to be "political prisoners", and their jailing triggered large protests by tens of thousands of PiS supporters.

Duda, a PiS ally, had pardoned both politicians after they were first sentenced in 2015 but Poland's Supreme Court deemed his move invalid, saying a presidential pardon could not be granted before a final ruling in the case was issued.

The two men then served in the nationalist PiS government but the Supreme Court said last year the case should be reopened. They were sentenced to two years in prison in December, when a new centrist coalition took power in Poland.

Within days of their imprisonment, Duda announced that he had started the process of pardoning them for a second time.

"For me, they have always been pardoned, but taking into account the social unrest, I decided to initiate the (new) pardon proceedings," Duda said in a statement.

"I appeal to the justice minister for the immediate release of both gentlemen from prison."

Earlier on Tuesday, Justice Minister Adam Bodnar, who is also the prosecutor general, said the two men should not be pardoned but his opinion is not binding the president.

New Prime Minister Donald Tusk has vowed to undo some PiS policies and to punish officials accused of wrongdoing during their time in office. Tusk says he wants to bring Poland back into line with European Union democratic standards after eight years of PiS rule that featured regular clashes with Brussels over judicial, media and other reforms.

(Reporting by Marek Strzelecki, Pawel Florkiewicz and Anna Koper; Editing by Gareth Jones and Richard Chang)