JOHANNESBURG — Angola’s ruling party has won the national election but lost ground to the opposition, the electoral commission said Friday, as the oil-rich but impoverished African nation faces its first change of leadership after nearly four decades.

Defense Minister Joao Lourenco will replace President Jose Eduardo dos Santos after 38 years in power. The victory for the ruling MPLA party represents continuity, though some observers hope Lourenco, a dos Santos loyalist who has pledged to fight widespread corruption, will work on transparency despite an entrenched elite that includes the dos Santos family.

The 74-year-old dos Santos is expected to remain head of the ruling party. Lourenco, 63, is a former governor who fought in the war against Portuguese colonial rule as well as the long civil war that ended in 2002.

The MPLA won the election with 61 percent of the vote, the country’s election commission said after 98 percent of votes from Wednesday’s election were counted. The MPLA had four million votes, while the leading opposition UNITA party had 1.8 million votes, or nearly 27 percent, election commission spokeswoman Julia Ferreira said. About 23 percent of eligible voters did not go to the polls.

While the ruling party defeated UNITA, its former foe during Angola’s devastating civil war, by a wide margin, it has lost popularity since beating its rival with 72 percent of the vote in the 2012 election.

The MPLA will get 150 seats in the 220-seat National Assembly, or 25 fewer than in the previous legislature, according to the Portuguese news agency Lusa. UNITA’s share of seats rises from 32 to 51.

Some 9.3 million Angolans were registered to vote for the legislature; the winning party then selects the president. The 2010 constitution abolished a direct vote for president.

The opposition made big inroads in populous Luanda province, which includes the capital of the same name. The MPLA won a big majority there in 2012 but got 48 percent this time; UNITA and another opposition group, CASA-CE, had a combined 50 percent. The MPLA had 59 percent in Luanda province in 2012.

Heavily reliant on oil, Angola’s economy has weakened because of the global fall in commodity prices. The opposition sought to capitalize on what it said was growing discontent among the country’s young population.

Angolan rights activists have alleged that the MPLA unfairly used state machinery ahead of the election, noting that most media coverage focused on the ruling party’s campaign. Opposition parties said there were irregularities ahead of the voting, an allegation denied by the ruling party.

Election officials said the vote went smoothly despite minor problems and delays.


Follow Christopher Torchia on Twitter at www.twitter.com/torchiachris