Former president Jacob Zuma will have to pay back millions of rand of taxpayer money spent on him fighting corruption charges for more than a decade.

The high court in Pretoria on Thursday found that the agreement between Zuma and the Presidency for the state to cover legal costs incurred in his personal capacity was invalid and set it aside.

It is a devastating blow for Zuma, whose decade in power was mired in allegations of corruption and weakening of state institutions. The ruling means his Stalingrad approach of using court applications to avoid charges of corruption, fraud and money laundering will be harder to sustain without state funding.

The state was not liable for the legal costs incurred by Zuma in his personal capacity "in criminal prosecutions instituted against him, in any civil litigation related or incidental thereto and for any other associated legal costs", deputy judge president Aubrey Ledwaba said.

Ledwaba ordered the state attorney to calculate the legal costs incurred by Zuma in his personal capacity in the graft case and "take all necessary steps, including the institution of civil proceedings", to recover the money.

Zuma was also ordered to pay the costs of applications brought by the DA and EFF.

So far, the state has paid between R15m and R32m in legal costs for Zuma. Earlier in 2018, Zuma pleaded poverty, saying if the state did not pay his legal fees he would not have the means to defend himself. It is likely he will appeal the ruling.

The DA and the EFF approached the court for a declaratory order that it was illegal to pay Zuma’s legal fees and to order the state attorney to determine how much money was paid in the process and then recover it from him.

The former president is facing 16 charges of fraud, corruption, money laundering and racketeering stemming from 783 alleged payments to him in relation to the arms deal when he was KwaZulu-Natal MEC of economic affairs and tourism. Charges were dropped in 2009 and reinstated earlier in 2018.

He recently lodged an application for a permanent stay of prosecution and will appear in court again in May 2019.

Over legal fees, Zuma and his predecessor Thabo Mbeki agreed that the State Attorney Act authorised the state to pay for the president’s litigation. Section 3 of the Act authorises the state attorney to act on behalf of the government and perform the work ordinarily performed by attorneys and other legal representatives in court.

However, Ledwaba said this did not provide for the appointment of private legal representation for government officials facing criminal charges and related civil litigation in their private capacities. He said the corruption charges levelled against Zuma had nothing to do with any of the official functions he was required to perform as an MEC or as president, and that the alleged payments were solely for his own benefit.

Ledwaba said it was in the public interest that allegations relating to the abuse of public office, such as corruption and fraud, be pursued to ensure public accountability and to promote good governance.

"If the state is burdened with high legal costs of those public office bearers who are charged with such crimes, the taxpayer bears that burden and poor communities continue to be denied access to essential services, as the states’ resources are being diverted in funding the defence of public office-bearers charged with such crimes, in this instance, financially assisting Mr Zuma to have litigated on a most luxurious scale."