The United States' top military officer has told American troops on a surprise visit to Baghdad that the momentum in the battle with the Islamic State of Iraq and the Levant (ISIL) was "starting to turn", but predicted a drawn-out campaign lasting several years.

General Martin Dempsey, chairman of the Joint Chiefs of Staff, was on Saturday visiting Iraq for the first time since President Barack Obama responded to ISIL advances this summer by ordering troops back into a country they left in 2011.

Hours earlier, an Iraqi army colonel said security forces appeared close to retaking the country's biggest refinery at Beiji, which has been under siege for months by ISIL.

Obama last week authorised roughly doubling the number of American ground forces as the military expands the reach of its advisers after slowing ISIL's advances with US air strikes.

Dempsey told the troops the US military had helped Iraqi and Kurdish forces "pull Iraq back from the precipice", Reuters news agency reported.

"And now, I think it's starting to turn. So well done," Dempsey told a group of Marines at the US embassy in Baghdad.

ISIL has captured swathes of territory in both Iraq and Syria, where the United States is also conducting air strikes with its allies in pursuit of Obama's declared objective to "degrade and destroy" the group.

'Bunch of midgets'

Dempsey said it had been crucial to show ISIL was not an unstoppable, 10-foot-tall force and instead "a bunch of midgets running around with a really radical ideology".

He was hardly triumphant, however. Earlier, he visited a Joint Operations Centre and watched a live video feed of a location showing Islamic State's black flag waving.

Thirty-six people were kidnapped by ISIL in western Iraq on Saturday, security sources said, members of the same tribe reportedly massacred in the hundreds by the group recently.

Live Box 2014108135930757185

Dempsey repeatedly made the point that military force could not root out ISIL unless Iraq's government manages to work across the Sunni-Shia divide.

Building trust would take time. So would the US mission, he said.

"How long? Several years," said Dempsey.

About 1,400 US troops are now in Iraq. Obama's new authorisation allows for deployment of up to 3,100.

After meeting senior Iraqi officials in Baghdad including Prime Minister Haider al-Abbadi, Dempsey travelled to Erbil, capital of the Kurdistan semi-autonomous region in the north. 

Source: Reuters