JOHANNESBURG — South Africans voted on Wednesday in elections that are expected to see the ruling African National Congress return to power despite a vigorous challenge from opposition parties seeking to capitalize on discontent with corruption and economic inequality.


Many people lined up before polling stations opened at 7 a.m. for the fifth all-race elections in South Africa since the end of white minority rule in 1994. Polls close at 9 p.m. and the first results were expected around midnight. South Africa’s election commission said it would declare final results no earlier than Saturday, allowing time to address any objections to the process.


Some 22,000 voting stations were operating at schools, places of worship, tribal authority sites and hospitals, and several dozen vehicles serving as mobile voting stations were heading to remote areas. About 25 million South Africans, roughly half the population, have registered to vote in the parliamentary elections that will also determine the president.


The government urged South Africans, particularly young people with the opportunity to vote for the first time, to go to the polls early to avoid bottlenecks later in the day. Wednesday was declared a public holiday to encourage voting. Nearly 2,000 military personnel are assisting police to make sure that the elections are peaceful around the country.


Retired archbishop Desmond Tutu cast his vote in Cape Town and said South Africans should be thankful that they can vote peacefully.


“I’m thinking of Ukraine. I’m thinking of South Sudan, you know, all of those things happening there,” the South African Press Association quoted Tutu as saying. Recalling the violent struggle against white minority rule that brought about the country’s democracy, he said: “People were imprisoned. People suffered. So we mustn’t waste it. We must keep remembering we got this at a very great price.”


The African National Congress, which led the fight against apartheid, has dominated politics since Nelson Mandela was elected as South Africa’s first black president in 1994. On the ruling party’s watch, millions of people have gained access to water and other basic services, but protests routinely erupt in areas where residents say the government has ignored their needs.


There is also increasing concern about corruption. President Jacob Zuma has become enmeshed in a scandal surrounding more than $20 million in state spending on his private home in the Nklanda area, though he denies any wrongdoing and has promised to work against graft. Zuma voted on Wednesday after standing in line at a primary school in Nkandla, urging other South Africans to do the same because it was “probably the most important thing to do in this democracy.”


In the last election in 2009, the African National Congress fell just short of a two-thirds majority. Its main rivals this year are the Democratic Alliance, a centrist party led by former journalist and anti-apartheid activist Helen Zille, and the Economic Freedom Fighters, headed by Julius Malema, a former head of the ruling party’s youth league who wants to redistribute wealth to the poor.


There were scattered incidents of delays and disruption at voting stations, but overall the election was running smoothly, said Mosotho Moepya, chief electoral officer at South Africa’s election commission.


Electoral officers had to help the first inmate to vote at the Witbank Corrections Center, a prison in South Africa’s Mpumalanga province, after he stepped out of the voting booth and said, “I don’t know how to do this,” the press agency reported. The sound of keys and the clatter of handcuffs filled a passage as prisoners were uncuffed before entering the voting station. Smiling widely, some prisoners placed green ID books in their shirt pockets after voting.


Three voting tents were set on fire during overnight protests in Bekkersdal, a township in South Africa’s most populous province, Gauteng, where residents have complained about what they describe as inadequate government services, according to Eyewitness News, a South African media outlet. Dozens of police and military vehicles have deployed in Bekkersdal in recent days.


Two ruling party officials tasked to monitor a polling station in the Northern Cape province were killed in a car accident early Wednesday, local media quoted party officials as saying.


In Itsoseng town, west of Johannesburg, first-time voter Julia Phokompe, 28, cast her ballot at a voting station set up in a church.


“It’s a feeling I can’t explain,” SAPA quoted Phokompe as saying. “I think I’ve made a huge difference in my life.”