JOHANNESBURG - South Africans on Sunday celebrated 20 years of democracy with song, prayer, and praise for those who guided their country into a more peaceful, tolerant era, although some noted that economic inequality and other problems have undermined the nation's promise since the first all-race elections ended white rule on April 27, 1994.

The focus of the Freedom Day commemorations was in Pretoria at the Union Buildings, the century-old government offices where President Jacob Zuma and dignitaries, including foreign diplomats, gathered to reflect on the long struggle against apartheid and ensuing efforts to build a better country.

The anniversary precedes elections May 7 that are likely to see the ruling African National Congress return to power with a smaller majority, reflecting discontent with the movement that opposed white domination before its candidate, Nelson Mandela, became South Africa's first black president.

In a speech, Zuma said South Africa had a good story to tell, referring to its stable electoral system, its constitutional commitment to human rights, as well as advancements in health care, welfare grants, and water and electricity in the last 20 years. Close to three million houses have been built since 1994, women play a more prominent role in public life, and crime has declined, even as it remains an issue of "serious concern," he said.

"We must not deny or downplay these achievements, regardless of our political differences or contestation at any given time, including the election period," said Zuma, who has been criticized because more than $20 million in state funds were spent on upgrading his private rural home. The scandal comes amid inequality between rich and poor that the government says is partly a legacy of old racial divisions, noting that the income of the average white household is six times that of a black one.

Candidate Julius Malema, the expelled head of the ruling party's youth league and now leader of an upstart party that wants to redistribute wealth, has told supporters that events surrounding Freedom Day, which is a national holiday, are a sham because many poor South Africans still lack basic services. "For as long as you don't have your dignity back, you have nothing to celebrate," Malema said this week, according to local media.

The mood was festive at the Pretoria ceremony, where balloons were on display and many people waved small South African flags. There was a military gun salute and a fly-over by air force planes. Messages of congratulations for the 20th anniversary of democracy came from around the world.

But many of the messages delivered in South Africa reflected the rough-and-tumble of an election season.