Wounded Islamic State fighters retreat from Baiji oil refinery, Iraqi officials say Iraq's army chief, General Babakir Zebari (right) meets General Martin Dempsey at the Defence Ministry in Baghdad. Baghdad: The top United States military officer, on a surprise visit to Baghdad, has said the momentum in the battle with Islamic State was "starting to turn," but the campaign would probably last several years. General Martin Dempsey, chairman of the Joint Chiefs of Staff, was on his first visit since the beginning of the American-led military campaign against the extremists. The Iraqi government and allied militia leaders said they had recaptured control of a major refinery under siege for months by the Islamic State fighters, the most significant advance in several weeks of fighting to drive out the group. Battlefield: A column of smoke rises from an oil refinery in Baiji in June. According to Reuters news agency, General Dempsey told a group of troops at the US embassy in Baghdad on Saturday that US forces had helped "pull Iraq back from the precipice." And now, I think it's starting to turn. So well done," he said. He described IS militants as "a bunch of midgets running around with a really radical ideology." But he said IS could not be defeated by the US alone. The campaign could take "several years," he said, and stressed the importance of the Iraqi government building trust between Sunnis and Shias. Islamic State fighters began withdrawing from the area around the Baiji refinery in northern Iraq on Saturday, Iraqi officials said. The retreat would mark the end of the group's month-long siege at a strategic oil installation, and a significant victory for pro-government forces. It remained unclear if Iraqi forces had passed through the gates of the refinery - Iraq's largest - on Saturday afternoon. Iraqi security officials gave conflicting reports on whether police and army troops had entered the facility. Islamic State militants surrounded the Baiji refinery, 177 kilometres north of Baghdad, in June, trapping pro-government forces inside. But a contingent of Iraqi soldiers and government-aligned militia fighters held out against the jihadists, who staged repeated attacks in a bid to seize the terminal. Police Brigadier General Khalil Ramal Ahmed said on Saturday that as many as 400 police had arrived at the refinery from the south after the militants went into full retreat. However, a spokesman for Asaib ahl al-Haq, a government-aligned Shiite militia with forces inside the refinery, said the siege had not yet been broken. Pro-government forces "are very close, just a few metres away," spokesman Naim al-Aboudi said on Saturday. He said the jihadists had planted dozens of improvised explosive devices to slow the government advance. "They have many wounded and they are retreating," he said of the Islamic State fighters. But we are not inside yet. Iraqi forces had staged a major offensive backed by United States air strikes to retake the nearby town of Baiji from the militants, eventually seizing the area amid fierce fighting. Baiji is the largest town to be recaptured from Islamic State fighters since the group launched its offensive across northern Iraq in June, overrunning major urban centres like Mosul and Tikrit. The Islamic State group continues to make gains in western Iraq's Anbar province, the heartland of the Sunni insurgency against US and later Iraqi government forces in recent years. But the government's progress in Baiji is a serious blow to the militants in the north. Their blockade of the refinery had taken much of the country's oil production off line, leading to reduced supplies for domestic consumption. The US government is set to boost the number of troops it will deploy to Iraq to advise and assist Iraqi forces in the fight against Islamic State. The 1500 added troops will roughly double the size of the force the US government has dispatched since June.