JOHANNESBURG — South Africa's Equality Court on Wednesday restricted the display of the country's old apartheid-era flag, ruling that its gratuitous use amounts to hate speech and racial discrimination.

Judge Phineas Mojapelo said the ruling was not a complete ban, saying use of the flag is protected by law for artistic, academic, journalistic or other purposes deemed in the public interest.

The judge criticized those who continued to wave the apartheid-era flag.

"Those who display the old flag choose deliberately to not only display the old flag, but also consciously and deliberately choose to not display the new, multiracial flag," said Mojapelo. "They choose oppression over liberation."

He said those who publicly display the flag should not be arrested, but should face deterrents such as fines or terms of community service.

The orange, white and blue flag of South Africa's previous white-minority regime, which enforced the system of racial discrimination known as apartheid, was replaced by a new flag when the country achieved majority-rule democracy in 1994.

However, some conservatives and right-wing groups continued to display the apartheid-era flag, notably at political gatherings or sometimes during rugby matches.

The Nelson Mandela Foundation, the custodian of former president Nelson Mandela's archives and legacy, asked the court to rule that displays of the old flag constitute hate speech and discrimination based on race.

Mandela, South Africa's first black president after decades of white-minority rule and who died in 2013, is credited with spearheading the country's peaceful transition to full-rights for all citizens.

South Africa's human rights commission joined the application, arguing that those waving the old flag felt nostalgia for the apartheid days.

The move to ban the old flag was opposed by Afriforum, a group representing the South Africa's white Afrikaner minority, which argued that the ban would infringe freedom of speech and expression.

The ruling was hailed as a "national victory," by Dakota Legoete, the spokesman for South Africa's ruling party, the African National Congress. He said the ruling as similar to the banning of the Nazi swastika in Germany.

The Nelson Mandela Foundation welcomed the ruling.

"The judge was clear that we have to work together with others, including Afriforum, to do what the Constitution says we must do," Mandela Foundation CEO Sello Hatang said at the courthouse immediately following the ruling. "We must be a nation that celebrates our diversity instead of fighting over our differences."

In a statement, the Mandela Foundation said South Africa "needs an opportunity to heal from the wounds of the past. ... This means looking at our history and calling apartheid a crime against humanity and a gross human rights violation. Without recognizing what has happened, we will forever be haunted by our history."

The foundation said that "gratuitous displays of the old flag express a desire for black people to be relegated to labor reserves, a pining for the killing, the torture, the abductions, a melancholia for the discrimination, the death squads, the curfews and the horrific atrocities committed under the flag."

Afriforum's Ernst Roets said his organization is not convinced that displaying the flag amounts to hate speech.

"As Afriforum we do not display the flag and we actively discourage people from displaying the flag," said Roets. "We cherish freedom of expression and for us displaying the flag is not sufficient ground for hate speech. For it to be hate speech, it must be coupled with a call to action to inflict harm."