When Nelson Mandela inaugurated the court that guards South Africa’s post-apartheid constitution in 1995, he warned that it would be tested not only by “direct assaults” but also “insidious corrosion”.

“The highest and the most humble in the land all, without exception, owe allegiance to the same document, the same principles,” and the court would have a lofty but also lonely task to ensure that they did, Mandela said.

Nearly 30 years later, the black, green and red robed justices of the South African constitutional court are widely regarded as having passed Mandela’s test. This week, they quoted Mandela’s words as they sentenced Jacob Zuma, the former president who dismissed them as “a few lawless judges”, to 15 months in jail for defying their order to attend an inquiry into corruption.

The sentence astonished South Africans who had long thought that the culture of impunity in the ruling African National Congress would never end even under Zuma’s successor, Cyril Ramaphosa. The judgment confirmed the status of the 11-member constitutional court and the judiciary as a bulwark of democracy.

“A lot of people are surprised at how brave the constitutional court was,” said Khaya Sithole, an independent political analyst. “They prioritised the project of relegitimising the institution as the ultimate reference point in matters of law.”

In recent years other African judiciaries have also asserted their independence against political leaders. The highest courts in Kenya and Malawi have both overturned rigged election victories by incumbents, while this month a judge in the west African nation of Mauritania ordered the imprisonment of its former president in a corruption case.

Many in South Africa believed that Zuma would never face justice over the multiple scandals that marred his nine-year presidency, above all the claims that he helped the Guptas, a business family, ‘capture’ the state and loot its resources.

Dozens of witnesses have implicated Zuma at a commission of inquiry into corruption. He denies wrongdoing, as do the Guptas. After walking out of his testimony, Zuma then also scorned the constitutional court. In one 21-page letter Zuma, who retains strong support among ANC members and in his home state of Kwazulu Natal, threatened an uprising against “judicial corruption”.

Even 15 months in jail “cannot properly capture the damage” of Zuma’s onslaught on the image of the judiciary, said Sisi Khampepe, the acting deputy chief justice, as she read out the judgment. “He owes this sentence in respect of violating not only this court, nor even just the sanctity of the judiciary, but to the nation he once promised to lead and to the constitution he once vowed to uphold.”

While a minority of justices said that Zuma should have received a full criminal trial before being jailed, they agreed that he was in contempt of court and should be sentenced one way or the other. Mzwanele Manyi, Zuma’s spokesperson, told local media on Wednesday that Zuma’s rights had been denied. “He has a criminal sentence but he was not afforded the rights that other criminals are afforded,” he said. Zuma has until Sunday to hand himself in. If not, the police will seek to arrest him at his homestead in KwaZulu-Natal.

Analysts said that Zuma appears to have misjudged South Africa’s courts, which have successfully withstood the tactics he used to weaken other state bodies. During his nine-year rule until 2018, the former president installed cronies in institutions such as the revenue service, the national prosecuting authority, state companies and parliament. He had less sway over the constitutional court because he could only appoint justices from a shortlist chosen by a special commission after public hearings.

South Africa’s courts also have an extensive appeals process and require judges to explain their decisions in detail, protecting against undue influence, said Mbekezeli Benjamin, a researcher for Judges Matter, a judicial watchdog. “The judiciary is small and quite tight-knit,” he said. “These mechanisms make it not as easy as other institutions to infiltrate and try to influence.”

For the judges, Zuma was attacking much more than a court but also a symbol of the country’s struggle to overcome the history of apartheid, where for hundreds of years blacks and whites were not equal under the law.

Years after its inauguration, the court moved into a new building, symbolically hewn from the bricks of an old Johannesburg prison for political opponents of colonial rule and apartheid, including Mandela. As part of the building’s design, the justices sit just below ground level, allowing ordinary South Africans outside to peer down on them. The court is “where the constitution of South Africa is given life,” Benjamin said.

Lawyers regard the Johannesburg court as one of a select group of institutions that has adhered to their constitutional mandate. These include the central bank and its public protector, or government ombudsman, who originally called for the state capture inquiry to be set up.

The ruling on Zuma is not the court’s only high-profile decision this year. It threw out a law allowing state surveillance of journalists. On Thursday, it cleared Ramaphosa of misleading parliament in a political donations case.

The Zuma ruling “is a very difficult political decision, and there are huge implications for someone as popular as Zuma to go to jail . . . but the law, as [the justices] found it, says that he must,” Benjamin said.

“It’s just difficult to feel sorry for the man — because he just dug his own grave,” Sithole said. Zuma’s defiance and attacks on the judiciary “may last a couple of days or a couple of tweets” longer, Sithole added. “But he will still be behind bars at the end of it all.”