By Daren Butler and Isabel Coles

ISTANBUL/ERBIL (Reuters) - Turkey said on Monday it would not withdraw hundreds of soldiers who arrived last week at a base in northern Iraq, despite being ordered by Baghdad to pull them out within 48 hours.

The sudden arrival of such a large and heavily armed Turkish contingent in a camp near the frontline in northern Iraq has added yet another controversial deployment to a war against Islamic State fighters that has drawn in most of the world's major powers.

Ankara says the troops are there as part of an international mission to train and equip Iraqi forces to fight against Islamic State. The Iraqi government says it never invited such a force, and will take its case to the United Nations if they are not pulled out.

Washington, which is leading an international coalition against Islamic State that includes Turkey, Arab states and European powers like Britain and France, has told Ankara and Baghdad to resolve the standoff, and says it does not support deployments in Iraq without Baghdad's consent.

The Turkish troops' presence is an embarrassment for Iraqi Prime Minister Haidar Abadi, under strong pressure from powerful Iran-backed Shi'ite political groups to kick them out.

Shi'ite parties linked to militia groups armed and funded by Iran have also complained about U.S. plans to station special forces in Iraq to conduct raids and guide bombs against Islamic State. Political pressure on Abadi could make those plans more difficult to carry out.

Political analysts saw last week's deployment in northern Iraq by Turkey, which has the second biggest army in NATO, as a bid to assert its influence in the face of increased Russian and Iranian involvement in Syria and Iraq.

"Turkey seems to be angling to prove to the Russians and Iranians that they will not be allowed to have either the Syrian or Iraqi war theaters only to themselves," said Aydin Selcen, former consul general of Turkey in Erbil, the capital of Iraq's autonomous Kurdish region.

Story continues

OUR DUTY

The troops arrived on Thursday with tanks and armored personnel carriers at a camp in territory held by Iraqi Kurds near the Islamic State-held northern Iraqi city of Mosul. Ankara said they were there to help protect a training mission close to the front line.

"It is our duty to provide security for our soldiers providing training there," Turkish Foreign Minister Mevlut Cavusoglu said in an interview on Turkey's Kanal 24 television.

"Everybody is present in Iraq ... The goal of all of them is clear. Train-and-equip advisory support is being provided. Our presence there is not a secret," he added.

Abadi has called the Turkish deployment a violation of Iraqi sovereignty. Government spokesman Saad al-Hadithi said Iraq was still waiting for Turkey to respond officially.

"In case we have not received any positive signs before the deadline we set for the Turkish side, then we maintain our legal right to file a complaint to the Security Council to stop this serious violation to Iraqi sovereignty," he said.

A senior Turkish official said Baghdad's objections had come as a surprise: "There was no single development ... that happened without informing the central government."

"The military personnel for training will stay. Not because we want them (there) particularly but because there is a demand from the Iraqi side. The discussion with the central government still continues," the official told reporters.

He said the total number of Turkish troops across Iraq was much less than 1,000 soldiers, with some having arrived from Turkey and others sent to the base from other parts of Iraq.

Islamic State militants overran Mosul, Iraq's main northern city and home to around 2 million people, in June 2014. An expected counter-offensive by Iraqi forces has been repeatedly postponed because they are involved in fighting elsewhere.

The U.S.-led coalition has been staging air strikes on Islamic State bases in both Iraq and Syria for more than a year.

Russia joined the regional conflict with air strikes of its own on Syria two months ago, and like Iran is allied to Syria's President Bashar al-Assad, who is opposed by Turkey, the United States and their allies. Turkey shot down a Russian warplane last month, causing a breakdown in relations with Moscow.

IRAQI ULTIMATUM

Brett McGurk, U.S. President Barack Obama's envoy to the global coalition to counter Islamic State, said on Twitter that Washington did not support missions in Iraq without permission of Baghdad, which he said also applied to U.S. missions there.

The camp occupied by the Turkish troops is being used by a force called Hashid Watani, or national mobilization, made up of mainly Sunni Arab former Iraqi police and volunteers from Mosul.

It is seen as a counterweight to Shi'ite militias that have grown in clout elsewhere in Iraq with Iranian backing, and was formed by former Nineveh governor Atheel al-Nujaifi, who has close relations with Turkey. A small number of Turkish trainers were already there before the latest deployment.

The government of Iraq's autonomous Kurdish region, whose security forces control the area where the Turks are deployed, backed up Ankara's explanation: Thursday's deployment was intended to expand the capacity of the training base, said Safeen Dizayee, Kurdish government spokesman.

"The increase of personnel requires some protection."

Although Turkey is strongly suspicious of Kurds in Syria, it has good relations with Iraq's Kurdish leader Massoud Barzani.

"Turkey, working through the Nujaifis and the Barzanis, is trying to establish its own sphere of influence in northern Iraq," said Aaron Stein, senior fellow at the Atlantic Council.

(Additional reporting by Humeyra Pamuk in Istanbul, Ahmed Rasheed in Baghdad, Orhan Coskun and Tulay Karadeniz in Ankara; Writing by Nick Tattersall; Editing by Pravin Char, Peter Millership and Peter Graff)