(Adds details)

RABAT, Oct 10 (Reuters) - Morocco's King Mohammed on Monday named moderate Islamist leader Abdelilah Benkirane as prime minister for a second term after his party won the most seats in last week's election, a senior party member said.

After five years in government, the Justice and Development Party (PJD) party won 125 seats while the rival Authenticity and Modernity Party (PAM) took 102, in a tight race for the 395-seat parliament that will complicate formation of a coalition.

The elections were a test for Morocco's constitutional monarchy, five years after the king devolved some powers to an elected government to ease Arab Spring-style protests demanding democratic change. The king still holds most executive authority and names the premier from the winning party in elections.

"I can confirm his majesty named him as the new prime minister," Mustapha Ramid, outgoing justice minister and a senior PJD party official, told Reuters, after attending the nomination of Benkirane in Casablanca.

Benkirane confirmed his nomination to local news websites.

Under Morocco's multi-party system, no one party can secure an outright majority, and must negotiate with others to form a coalition government. The PAM's strong position means the PJD must join with at least three other parties to have a house majority.

Since being appointed prime minister in 2011, Benkirane has pursued economic reforms to reduce the budget deficit and tackle subsidies. The PJD has been popular for its anti-corruption message. No party in the vote directly challenged the palace.

The PAM, founded by a close friend of the king who is now a palace adviser, portrayed itself as a liberal alternative to Islamists. But critics say it was used by the royal establishment, uncomfortable about sharing power with Islamists, to push back PJD influence.

(Reporting by Aziz El Yaakoubi; writing by Patrick Markey; editing by Andrew Roche) ((pat.markey@thomsonreuters.com; +213-661-692993; Reuters Messaging: pat.markey.thomsonreuters.com@reuters.net))