Morocco's ruling party has dominated the North African kingdom's main cities in local elections, but trailed in total seats behind its main rival - the Party of Authenticity and Modernity (PAM) - with strong backing from rural areas, according to final poll results.
The elections were seen as an important test of the popularity of the government, which came to power after pro-democracy demonstrations led to reforms.
Some 30,000 local council seats and 700 regional council seats were contested by more than 140,000 candidates from at least 30 parties.
The Islamic Party for Justice and Development (PJD) took the most seats in the regional councils with 25 percent of the total, but fell short in the local councils, which are weighted towards rural areas.
PAM took 6,655 seats of the local councils, or 21 percent, while PJD won 17 percent and the conservative Istiqlal (Independence) Party took 5,106 seats, or 16 percent of the total.
RELATED: Morocco votes
The PJD took control of councils in the main cities of Casablanca, Tangier, Rabat, Fez, and Agadir with just under 16 percent of seats - three times what it won in the 2009 local contests.
The ministry reported a voter turnout of 53 percent on Friday.
PAM was created in 2008 by one of the king's counsellors and it dominated local elections the following year.
It performed poorly, however, in the 2011 parliamentary elections amid Arab Spring-inspired calls for reform. Those elections were dominated by the PJD which went on to form a government.
Morocco's ruling party, which was the first to openly promote Islamic values, have played down religious issues in their campaigns and preferred to focus on combating corruption and unemployment.
The party has preserved its popularity despite implementing austerity measures and cutting energy subsidies to reduce the budget deficit.
Political analyst Maati Monjib said the PJD's success with urban voters is a reflection of their anti-corruption stance and a belief they are anti-status quo in a country still dominated by the monarchy.
"The PJD are still seen as anti-system and are not associated with the corruption of the regime," he said.