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 on 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 retained 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. The second largest opposition party, the Economic Freedom Fighters, called on South Africans to protest if parliament failed to remove the president.

While parliament has the power to remove him, the ANC 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 ANC's 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 also said that 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.

Zuma "failed to uphold, defend, and respect the constitution as the supreme law of the land," Mogoeng said.

In a statement, the ANC 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."

Zuma is already under scrutiny because of allegedly improper links to the Guptas, a wealthy business family in South Africa. Questions about the extent of the Gupta's influence have exposed some divisions within the ruling party, particularly after the country's deputy finance minister said the Gupta family directly offered him the finance minister job in December, around the time that the incumbent, Nhlanhla Nene, was sacked in a move that rattled markets.

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 Public Protector is thus one of the most invaluable constitutional gifts to our nation in the fight against corruption," Mogoeng said, comparing the office to David fighting on behalf of the citizenry against the "most powerful and very well resourced Goliath."

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.