CAPE TOWN — South Africa on Monday took an important step toward restoring a more independent justice system, removing a chief prosecutor widely seen as an obstacle to reining in the country’s rampant corruption.

The prosecutor, Shaun Abrahams, the director of public prosecutions, was ordered to step down immediately by the country’s highest court, a decision that left room for South Africa’s president, Cyril Ramaphosa, to take a tougher stance on the endemic graft within his party, the African National Congress.

When he took office in February, Mr. Ramaphosa pledged to usher in a new era of clean government, which he would accomplish in part by clearing out officials tied to the abuses of his predecessor as president, Jacob Zuma.

With the power to name a new chief prosecutor, Mr. Ramaphosa can now put his stamp on the office that effectively determines “who or what gets prosecuted” in South Africa, said Sithembile Mbete, who teaches politics at the University of Pretoria.