South African President Jacob Zuma has lost two court cases in one day, both linked to corruption allegations.
Pretoria's High Court ordered Mr Zuma to set up a judicial inquiry, calling him "seriously reckless" for challenging recommendations by a watchdog in a case against him.
In the second case, a judge ruled he had abused the judicial process by trying to block a report on corruption, ordering him to pay legal fees.
Mr Zuma quits as ANC leader next week.
The party is currently battling to choose Mr Zuma's successor as leader. He is due to remain as president until elections in 2019.
In his 10-year term he has been dogged by allegations of corruption, all of which he denies.
BBC Africa correspondent Andrew Harding says the South African judiciary is flexing its muscles, at a time of deepening anxiety about state corruption and apparent impunity.
In the first ruling, the court gave Mr Zuma 30 days to appoint an inquiry into allegations of corruption against him and his associates.
The inquiry was one of the recommendations on state influence-peddling by the country's anti-corruption watchdog, which the president had tried to challenge.
Judge President Dunstan Mlambo described Mr Zuma's attempt to challenge the rulings as "ill-advised" and an abuse of the judicial process.
As yet Mr Zuma has not commented on the decision.
In a separate case, Judge Mlambo also ruled that Mr Zuma had been unreasonable in trying to use the courts to block the publication of an explosive official report into high-level corruption, known as state capture.
He ordered Mr Zuma to pay all legal costs out of his own pocket.
Our correspondent describes this as a withering and unprecedented judgement against a sitting president.
The report's author, Thuli Madonsela, told Reuters after the verdict: "An allegation that the state has been captured in the interests of the president and his friends is an allegation that needs to be investigated immediately."
Mr Zuma has been accused of conspiring with a wealthy business family, the Guptas, to control lucrative state contracts.