The appointment of the chief prosecutor, who was given his job after former president Jacob Zuma removed his predecessor, is invalid and ordered that his replacement be made within 90 days.
Shaun Abrahams was appealing against an earlier High Court judgment that ruled that the removal of predecessor Mxolisi Nxasana was unlawful and that his own appointment be revoked.
Zuma faced a string of corruption allegations during his time in office, and Abrahams was accused by the opposition and rights groups of shielding the president from prosecution.
Zuma has denied wrongdoing and Abrahams denies protecting him from prosecution.
“Zuma’s removal of Nxasana was an abuse of power. Abrahams was a beneficiary of an abuse of power,” Judge Mbuyiseli Madlanga, who criticised Zuma for buying Nxasana out of office with a 17 million rand (one million dollars) payout.
“The inference is inescapable that he was buying Mr Nxasana out of office.”
Zuma, whose nine years in power were marked by economic stagnation and credit rating downgrades, resigned as President in February, reluctantly heeding orders by the ruling African National Congress.
The judge ordered that South Africa’s President Cyril Ramaphosa to appoint a National Director of Public Prosecutions within 90 days.
Several civil rights groups asked the Constitutional Court, the country’s highest, to confirm the previous ruling, and remove Abrahams from office.
Abrahams, who had kept his post pending the appeal, was not at the court. He did not immediately comment.