* Maliki demands court ruling before he will step aside
* PM-designate Abadi endorsed by Iran's supreme leader
* Europeans join U.S. in arming Kurds, study other aid
BAGHDAD, Aug 13 (Reuters) - Nuri al-Maliki stuck to his guns and refused to accept his removal as Iraq's prime minister on Wednesday, but his hold on power was tenuous as Iran's supreme leader, a long-time Maliki ally, publicly backed his replacement.
Taking to state television as acting premier, Maliki said the supreme court must rule on this week's move to ask his Shi'ite Islamist party colleague Haider al-Abadi to form a new government - a change that Iran, the United States and many Iraqis see as vital to halt the advance of Sunni militants.
But while the loyalty of at least some Shi'ite militia and government forces remains uncertain, there were further signs that Maliki, blamed for alienating the Sunni minority during his eight years in power, is isolated, even among fellow Shi'ites.
U.S. President Barack Obama - whose European allies followed his lead on Wednesday to arm Kurdish forces that have taken the recent brunt of fighting with the Sunni Islamic State - has already offered Abadi its endorsement. Washington lost patience with Maliki, who rose from obscurity during the U.S. occupation.
Iranian Supreme Leader Ayatollah Ali Khamenei, bound to Tehran's U.S. adversary by a common interest in curbing the rise of Sunni jihadists in Syria and Iraq, offered his personal endorsement to Abadi. He very publicly distanced himself in the process from Maliki, who has looked for support from Iran, where he spent years in exile opposing Sunni dictator Saddam Hussein.
"I hope the designation of the new prime minister in Iraq will untie the knot and lead to the establishment of a new government and teach a good lesson to those who aim for sedition in Iraq," Khamenei said in a statement on his website.
Iranian media carried reports that Khamenei sent an envoy last month to take part in discussions with Iraqi Shi'ite political and religious leaders to find an alternative to Maliki, who had held on since a parliamentary election in April despite being blamed by many for fuelling sectarian hatreds.
Those leaders, including Iraq's reclusive top cleric Grand Ayatollah Ali al-Sistani, last week rallied around Abadi, who long ran a British engineering company, as a compromise figure who could bring moderate Sunnis into power to cooperate on holding off the militant offensive in the north.
Maliki has complained to the Federal Court that, as leader of the largest bloc in the new parliament, he must by right be given the first chance to form a new government. The appointment by President Fouad Masoum of Abadi as prime minister-designate on Monday was therefore a breach of the constitution, he said.
"The violation that occurred has no value, and its consequences have no effect," Maliki said on television. "This government is continuing, and will not be changed except after the Federal Court issues its decision."
In theory, Maliki should continue as acting premier, with limited powers, until a new government is sworn in. He has had the personal loyalty of senior commanders of the police and armed forces as well as irregular Shi'ite militia units. It is unclear he would try to resist his removal by force, however. On Tuesday, he urged commanders to keep out of politics.
With ethnic Kurdish Peshmerga forces pushed back on the defensive by the Islamic State this month, France announced it was joining the United States in urgently supplying arms to the autonomous regional force, and EU officials said European Union foreign ministers could meet on Friday to discuss the crisis.
In addition to arming the Peshmerga and, in the case of Washington, bombing militant positions, Western powers have been trying to help aid agencies drop supplies and provide refuge for tens of thousands of people, many of them from non-Sunni communities, who have fled attacks by the Islamic State.
The militant group, which already controlled large parts of Syria and has announced a religious caliphate straddling the desert border, took advantage of political paralysis in Baghdad following April's election to seize huge swathes of territory.
That has been accompanied by an increase in sectarian violence elsewhere. In the city of Baquba, northeast of Baghdad, five Sunnis were killed on Wednesday when Shi'ite gunmen stormed a mosque and shot them as they prayed, security sources said.
(Additional reporting by Michael Georgy in Baghdad and Mehrdad Balali in Dubai; Writing by Alastair Macdonald; Editing by Will Waterman)