BAGHDAD (Reuters) - Iraq’s parliament demanded on Thursday that the government set a timeline for the withdrawal of foreign troops stationed in the country to help fight Islamic State (IS) insurgents, a ruling coalition lawmaker said.

A U.S.-led coalition was formed in 2014 and with thousands of troops and air support helped Iraqi security forces and a Kurdish-led Syrian militia roll back IS across large swathes of Iraq and Syria and destroy the cross-border caliphate set up by the jihadists. Iraqi Prime Minister Haider al-Abadi declared victory over IS in December.

IS has since reverted to a guerrilla-style insurgency and continues to carry out attacks on selected targets.

The Iraqi parliament’s demand underscores the balancing act Abadi must conduct between the United States and Iran, his two biggest military allies who are themselves arch-adversaries.

There are no Iranian regular forces in Iraq but there are Iranian-backed Shi’ite militia allied with Abadi’s government.

“Parliament voted for a decision to thank friendly nations for their support in defeating Islamic State and at the same time to demand the government set a timeline for the withdrawal of foreign troops,” lawmaker Husham al-Suhail told Reuters.

“It is up to the government to decide how long we need them here - one year, two years, it’s up to them.”

Thursday’s vote, backed by all but a handful of the 177 lawmakers present, was sponsored by lawmakers from the ruling Shi’ite Muslim bloc in parliament.

“The timing of the vote, right before the election, is a message from pro-Iran parties that they do not want American troops in Iraq forever,” said political analyst Ahmed Younis.

“They are achieving two things - pressure on Abadi’s government to expel foreign troops, as well as scoring political points before the election.”

Abadi is seeking a second term in parliamentary elections scheduled for May.

A spokesman for the coalition told Reuters the presence of its troops hinged on Iraqi government approval.

“Our continued presence in Iraq will be conditions-based, proportional to need, in coordination with and by the approval of the Iraqi government,” said U.S. Army Colonel Ryan Dillon.

The coalition says it has begun a transition from focusing on retaking territory to consolidating gains.

It has trained 125,000 members of the Iraqi security forces, 22,000 of which were regional Kurdish Peshmerga fighters, and helped retake almost a third of Iraq from Islamic State through air and logistical support.

The coalition has drawn criticism, however, for the number of civilian casualties resulting from air strikes. At least 841 civilians were killed this way as of January 2018. It says it goes to great lengths to avoid civilian casualties.