By Phil Stewart
BAGHDAD (Reuters) - The United States' top military officer told American troops on a surprise visit to Baghdad on Saturday that the momentum in the battle with Islamic State was "starting to turn", but predicted a drawn-out campaign lasting several years.
General Martin Dempsey, chairman of the Joint Chiefs of Staff, was visiting Iraq for the first time since President Barack Obama responded to Islamic State 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 Baiji, which has been under siege for months by Islamic State militants.
Obama last week authorized roughly doubling the number of American ground forces as the military expands the reach of its advisers after slowing the militants' advances with U.S. airstrikes.
Dempsey told the troops the U.S. military had helped Iraqi and Kurdish forces "pull Iraq back from the precipice".
"And now, I think it's starting to turn. So well done," Dempsey told a group of Marines at the U.S. embassy in Baghdad. Reuters accompanied him on the trip.
Islamic State 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 militants.
Dempsey said it had been crucial to show Islamic State 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 Center and watched a live video feed of a location showing Islamic State's black flag waving.
Thirty-six people were kidnapped by Islamic State in western Iraq on Saturday, security sources said, members of the same tribe massacred in the hundreds by the group recently.
Mortar attacks on oil and gas facilities wounded two people near the northern city of Kirkuk, oil officials said.
Dempsey repeatedly made the point that military force could not root out Islamic State unless Iraq's government manages to work across the Sunni-Shi'ite divide.
Building trust would take time. So would the U.S. mission, he said.
"How long? Several years," said Dempsey.
Dempsey, who also met top Iraqi officials, told Reuters he wanted to find out whether the Iraqis believed they could win recruits for a program the United States hopes to get under way next year to re-train Iraqi units.
"I want to get a sense from them on whether they believe our timeline is feasible," Dempsey said.
About 1,400 U.S. troops are now in Iraq. Obama's new authorization allows for deployment of up to 3,100.
After meeting senior Iraqi officials in Baghdad including Prime Minister Haider al-Abadi, Dempsey traveled to Arbil, capital of the Kurdistan semi-autonomous region in the north. U.S. troops will also train Kurdish forces.
(Editing by Michael Georgy, Sonya Hepinstall and Mark Trevelyan)