South Africa's President Jacob Zuma has made a U-turn in court over his refusal to repay some of the $23m (£15m) of state money used to upgrade his home.
His lawyer admitted he was wrong to ignore an anti-corruption watchdog's report to pay back money spent on features such as a swimming pool.
The opposition brought the case, hoping it will open the way for impeachment proceedings against the president.
Thousands of people protested outside court, shouting "Zuma must fall".
Police put up a strong show of force, as the protesters, led by Julius Malema's left-wing Economic Freedom Fighters (EFF), marched to the court in the main city, Johannesburg.
The protest was against "corruption and cronyism" in government, the EFF said.
The main opposition Democratic Alliance (DA) also organised its own demonstration.
The governing African National Congress (ANC) denounced the marches as a "political exercise".
The opposition parties want the Constitutional Court to rule that Mr Zuma flouted the constitution by ignoring a 2014 report by the anti-corruption watchdog, known as the Public Protector, that he should repay the money, as he had "unduly benefited" from the upgrade.
At the time, the police minister defended the expenditure as necessary security upgrades, saying the swimming pool was, in fact, a fire pool that could be used in the event a fire broke out at the residence in Mr Zuma's home village of Nkandla.
An amphitheatre, cattle enclosure and chicken run were also built.
Mr Zuma's lawyer Jeremy Gauntlett conceded in court that the report was "binding" on the president, and he was prepared to repay the money within 90 days.
However, he denied that Mr Zuma had violated the constitution.
Analysis: Milton Nkosi, BBC News, Johannesburg
The admission by Mr Zuma's lawyer was shocking: The president was legally bound to accept the findings of the Public Protector's report, entitled Secure in Comfort.
This was a massive U-turn, as Mr Zuma had until now argued that the report contained mere recommendations, lacking the status of a court order.
Looking at Mr Malema, I could only conclude that he was rubbing his hands with glee as the drama unfolded in court.
The EFF now smells blood - it hopes South Africa's highest court will go as far as to rule that the president breached the constitution and therefore violated his oath of office.
The opposition would then no doubt demand the president's impeachment.
For now, Police Minister Nathi Nhleko's position is most tenuous. He was at the forefront of the campaign to rubbish the Public Protector's report. It is difficult to see how he can remain in the post.
The hashtag #PayBackTheMoney, mirroring the slogan used by EFF members to taunt the president, has been trending in South Africa:
The saga has become a major political scandal, at one point sparking scuffles inside parliament.
EFF lawyer Wim Trengrove told the court the president had defied the Public Protector to unlawfully "enrich himself", South Africa's private News24 website reports.
"His conduct at the time and response to the report was in violation of the constitution," Mr Trengrove is quoted as telling the judges.
The case comes at a difficult time for Mr Zuma, who has also been under fire over his handling of the finance ministry, after he sacked two ministers in a week last year.
Many South Africans also accuse his government of not doing enough to tackle corruption and poverty.