(Adds details, comments throughout)

By Aziz El Yaakoubi and Patrick Markey

RABAT, Oct 8 (Reuters) - Morocco's ruling moderate Islamist party won most seats in Friday's parliamentary election, with a rival party that critics say is too close to the palace coming second in a tight race with 90 percent of votes counted, officials said on Saturday.

Elections for the House of Representatives were a test of Morocco's constitutional monarchy five years after the king devolved some limited powers to elected government to ease protests for democratic change in the kingdom.

The governing Justice and Development Party (PJD) won 99 seats while the Authenticity and Modernity Party (PAM) party had 80 seats, and the conservative Istiqlal party took 31 seats, according to the results announced by the interior minister.

Under Morocco's system no party can win an outright majority in the vote for the 395-seat parliament and the winner must form a coalition government. The king, who still retains most executive power, chooses a premier from the winning party.

The tight race will make coalition-building tough for the PJD even if they win the election. With PAM scoring high, the Islamists potentially need to partner with at least three other parties to secure a parliamentary majority.

The minister said counting for another 90 seats set aside for women and youth lawmakers was still ongoing.

Prime Minister Abdelilah Benkirane's PJD won the 2011 election, and he was appointed premier by the king. In five years he has pushed economic reforms to reduce the deficit and tackle subsidies. PJD has been popular for its anti-corruption message.

"The Moroccan people voted for PJD massively," Benkirane told reporters. "The PJD has proven today that being serious and truthful ... and being faithful to the institutions, especially the monarchy, is a winning currency."

PJD's main rival, PAM, founded by a close friend of the king who is now a palace adviser, had presented itself as a liberal alternative to Islamists.

The PJD is one of the only remaining Islamist parties leading a government after the Arab Spring revolts toppled long-standing leaders in Libya, Egypt and Tunisia and brought Islamist parties to political power.

But Morocco's main Islamist opposition group, Justice and Spirituality, and left-wing organisations, have boycotted elections in protest over the king's tight grip on power.

Campaigning was marked by accusations that the royal establishment, uneasy about sharing power with Islamists, was unfairly backing PAM as a way to roll back PJD influence. Palace officials denied any favouritism.

Hours before polls closed on Friday, the PJD accused local officials under the control of the Interior Ministry of trying to influence voters. The ministry has dismissed some claims and said it would investigate others.

The North African kingdom presents itself as a model for economic stability and gradual reform in a region where violence and instability are more the norm. Morocco's moderate Islamists have been symbols of co-existence rather than rebellion.

(Editing by Leslie Adler) ((pat.markey@thomsonreuters.com; +213-661-692993; Reuters Messaging: pat.markey.thomsonreuters.com@reuters.net))