The RNI won 102 of parliament's 395 seats, thrashing the PJD, which had headed the governing coalition for a decade but took just 13 seats.
Morocco's King Mohammed VI has appointed billionaire fuel tycoon Aziz Akhannouch as prime minister after his party came first in Wednesday's parliamentary election.
Akhannouch, a former agriculture minister, is one of Morocco's richest men with a fortune estimated at about $2 billion. He has led the liberal National Rally of Independents (RNI) party since 2016.
On Wednesday, RNI won 102 of the parliament's 395 seats as the vote share of the moderate Justice and Development party (PJD) that had been the biggest in the previous two elections collapsed.
Under reforms introduced in 2011, the king picks the prime minister from the largest party in parliament but retains veto power over cabinet members. In recent years he has taken back more powers within the palace walls, analysts say.
Changes to the voting system meant it was the first time Morocco's 18 million voters cast ballots in both parliamentary and local elections on the same day, in an effort to boost turnout.
Billionaire at helm
RNI is considered close to the palace and has been part of all coalition governments for the past 23 years except during a brief period between 2012 and 2013.
Akhannouch said in a speech after the election results were declared that he would "implement his majesty's vision."
Akhannouch, whose holding company operates in the fuel and gas distribution business, and was targeted by a consumer boycott campaign in 2018 over prices, has pushed RNI as a champion of social and economic reforms.
It must now build a governing coalition that can command a parliamentary majority of at least 198 seats.
The next-largest party after Wednesday's vote was PAM, which is also liberal and pro-establishment, with 86 seats.
PJD cries foul
The PJD, whose leader Saad Dine El Otmani had been prime minister since 2017, has complained of violations in the election including what it said was vote buying by rivals.
However, after securing only 13 seats compared to 125 in 2016 it has said it will go into opposition and not seek to join the next governing coalition.
Otmani and some other senior members have resigned their party posts.