BAGHDAD/KIRKUK- The Baghdad government recaptured territory across the breadth of northern Iraq from Kurds on Tuesday, making startingly rapid gains in a sudden campaign that has shifted the balance of power in the country almost overnight.

In the second day of a lightning government advance to take back towns and countryside from forces of the Kurdish autonomous region, Kurdish troops known as Peshmerga pulled out of the long disputed Khanaqin area near the Iranian border.

Government troops took control of the last two oilfields in the vicinity of Kirkuk, a city of 1 million people that the Peshmerga abandoned the previous day in the face of the government advance. A Yazidi group allied to Baghdad also took control of the town of Sinjar.

The government advances have redrawn the map of northern Iraq, rolling back gains by the Kurds who infuriated Baghdad last month by holding a referendum on independence.

The Kurds govern three mountainous northern provinces in an autonomous region, and have also held a wide crescent of additional territory in northern Iraq, much of which they captured after helping drive out Islamic State fighters.

Prime Minister Haidar Abadi ordered his troops on Monday to raise their flag over all Kurdish-held territory outside the autonomous region itself. They achieved a swift victory in Kirkuk, reaching the centre of the city in less than a day.

The fighting in one of Iraq's main oil-producing areas has helped return a risk premium to oil prices. After months of range-bound trading, benchmark Brent crude is now above $58 a barrel LCOc1 , up almost a third from its mid-year levels.

Oil officials in Baghdad said all the fields near Kirkuk were working normally on Tuesday after the last came under government control. Kirkuk is the base of Iraq's Northern Oil Company, one of the two giant state energy firms that provide nearly all government revenue.

DILEMMA FOR WASHINGTON

The advances create a dilemma for Washington, which has armed and trained both sides in its successful campaign to drive Islamic State fighters out of Iraq.

"We don't like the fact that they're clashing," U.S. President Donald Trump told reporters at the White House on Monday. "We've had for many years a very good relationship with the Kurds as you know, and we've also been on the side of Iraq."

So far most of the advances appear to have come unopposed, with Kurds withdrawing before government forces move in. There have been reports of just one major clash, in the early hours of Monday on the outskirts of Kirkuk.

In Kirkuk, one of Iraq's most diverse cities, members of the Turkmen ethnic group who have opposed Kurdish rule had celebrated on Monday, driving through the streets in convoys and firing weapons in the air.

By Tuesday, the once ubiquitous green, red and white Kurdish flag with a blazing yellow sun had vanished from the streets. U.S.-trained Iraqi special forces and local police patrolled to maintain order. Markets, shops and schools were open as normal.

Some Kurdish families who had left the city on Monday were already returning home. They said thousands of Kurdish fighters in convoys were lining up in a long queue attempting to flee Kirkuk towards the Kurdish regional capital Erbil, which clogged the road and made it difficult for civilians to leave.

For the Kurds, the loss of territory, particularly Kirkuk which Kurdish folklore views as the heart of their homeland, is a severe blow just three weeks after they voted to declare the independent state that had been their goal for decades.

"Our leaders abandoned us in the middle of nowhere. Our future is dark," said Malla Bakhtiyar, a retired schoolteacher in Kirkuk.

He said he tried to escape on Monday but returned with his wife and sons after an Arab neighbour phoned, begging him not to leave and assuring him the city was safe.

University lecturer Salar Othman Ameen blamed the Kurdish authorities for calling the independence referendum prematurely.

"We feel broken now. The referendum was a catastrophic decision...Our Kurdish leadership was supposed to think of the consequences before moving along with independence vote. Now we have lost what we have achieved over three decades."

The setbacks led to recriminations among the two main Kurdish political parties, which each control separate units of Peshmerga fighters. Officials in the KDP of Kurdish regional government leader Masoud Barzani accused the PUK of his longterm rival Jalal Talabani of "treason" for abandoning Kirkuk.

Talabani, who served as ceremonial Iraqi president in Baghdad from 2003-2014, died two weeks ago. His widow denied blame for the fall of Kirkuk and said her party had tried to avert the advance through contact with U.S. and Iraqi officials.

Barzani was expected to issue a statement calling on Kurdish factions to avoid "civil war", according to Kurdish Rudaw TV.

The advances were a second major triumph for Abadi, the soft-spoken Iraqi prime minister, months after his forces recaptured Mosul from Islamic State. Abadi had faced threats from Iran-backed Shi'ite armed groups to take matters into their own hands if he did not act decisively to take on the Kurds.

"If elections were held tomorrow, I would vote with ten fingers for Abadi. He succeeded in keeping Iraq a single state," said Adel Abdul Kareem, a Baghdad lawyer.

"When Kurdish leaders were threatening Baghdad, Abadi was always smiling," he said. "We did not expect he was hiding a tornado behind this smile. He proved he was a smart leader, and with his wisdom he won against Masoud (Barzani) with a knockout in the second round."

In Sinjar, home to the small Yazidi religious minority that faced genocide in 2014 when the area was captured by Islamic State fighters, a Yazidi group called Lalesh took control of the town after Kurdish Peshmerga withdrew.

"There was no violence. The Lalesh group moved after the Peshmerga pulled out," said a resident reached by telephone.

The decision by the Kurds to hold an independence referendum had angered neighbours Turkey and Iran. Washington, friendly to the Kurds for decades, had also called on them to cancel the vote, fearing it could trigger war.

(Additional reporting by Maher Chmaytelli; writing by Peter Graff; Editing by Richard Balmforth) ((peter.graff@thomsonreuters.com;))