JOHANNESBURG — For two years, South Africa's president brushed off a scandal over state spending on his private home, even when critics scoffed at the notion that a swimming pool and a chicken run were necessary security features. It took the country's highest court to bring him to account.

South African President Jacob Zuma “failed to uphold” the constitution when he didn't pay back some of the more than $20 million in state funds used to upgrade his rural home, South Africa's Constitutional Court ruled unanimously Thursday.

The ruling could significantly weaken the leader, who is fending off multiple accusations of alleged misconduct at the highest levels of government, though he still retains the support of powerful factions in his party, the African National Congress.

Until now, Zuma's political career has survived a string of scandals — from his acquittal for rape in 2006 to the most recent allegation that his friends have the freedom to appoint Cabinet ministers. Still, he has enjoyed the public support of the African National Congress, with the party's lawmakers repeatedly coming to his defense in parliament and at political rallies.

The main opposition party, the Democratic Alliance, said it would immediately begin impeachment proceedings against Zuma.

While parliament has the power to remove him, the African National Congress holds most of the seats, and ruling party lawmakers defeated a no-confidence vote against Zuma earlier this year. With 248 of the 400 seats in South Africa's parliament, according to the country's Independent Electoral Commission, the African National Congress' parliamentary majority is more than all the opposition parties' combined, meaning another vote against Zuma is unlikely to succeed.

Constitutional Court Chief Justice Mogoeng Mogoeng said parliament had failed in its obligations by not holding Zuma to account in the spending scandal.

Mogoeng said Zuma should not have ignored a state watchdog's recommendations that he reimburse state funds spent on his rural home, known as Nkandla.

The national treasury must calculate costs of upgrades unrelated to security at Zuma's home within 60 days, and the president must repay that amount within 45 days thereafter, the court said.

The police minister had previously compiled a report arguing that features like a large swimming pool and a chicken run contributed to the security of Zuma's compound. The police minister's presentation even included a video of firefighters displaying how the large swimming pool could be utilized in the event of an emergency.

In a statement, the African National Congress said it respects the judgment by the Constitutional Court and that it has “full confidence in the judiciary” and the rule of law in South Africa. In a separate statement, the South African government said Zuma also respects the ruling and “will in consultation with other impacted institutions of state determine the appropriate action.”

Much of the Nkandla case hinged on whether the findings of the state watchdog, the Public Protector's office, were legally binding.

The court said the watchdog's office, established in line with South Africa's post-apartheid constitution, was designed to be a champion of good governance.

The Constitutional Court also ruled that the president must reprimand ministers involved in the matter.

In 2014, a parliamentary committee, boycotted by opposition party lawmakers, had cleared the president.