By Ahmed Rasheed and Raheem Salman

BAGHDAD, Aug 3 (Reuters) - Islamic State fighters seized control of Iraq's biggest dam, an oilfield and three more towns on Sunday after inflicting their first major defeat on Kurdish forces since sweeping across much of northern Iraq in June.

Capture of the electricity-generating Mosul Dam, after an offensive of barely 24 hours, could give the Sunni militants the ability to flood major Iraqi cities or withhold water from farms, raising the stakes in their bid to topple Prime Minister Nuri al-Maliki's Shi'ite-led government.

"The terrorist gangs of the Islamic State have taken control of Mosul Dam after the withdrawal of Kurdish forces without a fight," said Iraqi state television.

The swift withdrawal of Kurdish "peshmerga" troops was an apparent severe blow to one of the only forces in Iraq that until now had stood firm against the Sunni Islamist fighters who aim to redraw the borders of the Middle East.

The Islamic State, which sees Iraq's majority Shi'ites as apostates who deserve to be killed, also seized the Ain Zalah oil field - adding to four others already under its control that provide funding for operations - and three towns.

Initially strong Kurdish resistance evaporated after the start of an offensive to take the town of Zumar. The Islamists then hoisted their black flags there, a ritual that has often preceded mass executions of their captured opponents and the imposition of an ideology even al-Qaeda finds excessive.

The group, which has declared a caliphate in parts of Iraq and Syria to rule over all Muslims, poses the biggest challenge to the stability of OPEC member Iraq since the fall of Saddam Hussein in 2003.

FIGHTING FOR TOWNS

On Sunday its members were also involved in fighting in a border town far away in Lebanon, a sign of its ambitions across the frontiers of the Middle East.

It controls cities in Iraq's Tigris and Euphrates valleys north and west of Baghdad, and a swathe of Syria stretching from the Iraqi border in the east to Aleppo in the northwest.

Iraq's Kurds, who rule themselves in a northern enclave guarded by the "peshmerga" units, had expanded areas under their control in recent weeks while avoiding direct confrontation with the Islamic State, even as Iraqi central government troops fled.

But the towns lost on Sunday were in territory the Kurds had held for many years, undermining suggestions that the Islamic State's advance has helped the Kurdish cause.

Witnesses said Islamic State fighters were also trying to take control of the town of Rabia near the Syrian border and were engaged in clashes with Syrian Kurds who had crossed the frontier after Iraqi Kurds withdrew.

The latest gains have placed Islamic State fighters near Dohuk Province, one of three in the autonomous Kurdish region, which has been spared any serious threat to its security while war raged throughout the rest of Iraq.

Since thousands of U.S.-trained Iraqi soldiers fled the Islamic State offensive, the Kurdish fighters were seen alongside Shi'ite militia to the south as the main lines of defense against the militants, who vow to march on Baghdad.

By calling into question the effectiveness of the Kurdish fighters, Sunday's advances may increase pressure on bickering Iraqi leaders to form a power-sharing government capable of countering the Islamic State.

LITTLE RESISTANCE

Two people who live near Mosul Dam told Reuters Kurdish troops had loaded their vehicles with belongings including air conditioners and fled.

Islamic State fighters attacked Zumar from three directions in pick-up trucks mounted with weapons, defeating Kurdish forces that had poured reinforcements into the town, witnesses said.

The Islamic State later also seized the town of Sinjar, where witnesses said residents had fled after Kurdish fighters put up little resistance. It was not immediately clear why the Kurds, usually known as formidable fighters, pulled back without a fight.

On its Twitter site, the Islamic State posted a picture of one of its masked fighters holding up a pistol and sitting at the abandoned desk of the mayor of Sinjar. Behind him was the image of a famous Kurdish guerrilla leader.

In a statement on its website, the Islamic State said it had killed scores of peshmerga, the Kurdish fighters whose name means "those who confront death". Those deaths could not be independently verified.

"Hundreds fled leaving vehicles and a huge number of weapons and munitions and the brothers control many areas," the Islamic State statement said. "The fighters arrived in the border triangle between Iraq, Syria and Turkey."

The Islamic State has systematically blown up Shi'ite mosques and shrines in territory it has seized, fueling levels of sectarian violence unseen since the very worst weeks of Iraq's 2006-2007 civil war.

The group, which shortened its name after June's offensive from the Islamic State in Iraq and the Levant (ISIL), has stalled in its drive to reach Baghdad, halting just before the town of Samarra, 100 km (62 miles) north of the capital.

ISLAMIC STATE ADVANCES

The Islamic State has been trying to consolidate its gains, setting its sights on strategic towns near oil fields, as well as border crossings with Syria, so that it can move easily back and forth and transport supplies.

So far, the Islamic State is not near the major oil fields of the northern city of Kirkuk, which were seized by the Kurds in the chaos that followed the Islamic State's advance. It controls part of a pipeline from Kirkuk to Turkey which has been idle for months because of its attacks in the area.

The Islamic State has capitalized on Sunni disenchantment with Maliki by winning support or at least tolerance from some more moderate Sunni communities in Iraq that had fought against al Qaeda during the U.S. "surge" offensive of 2006-2007.

Maliki's opponents say the prime minister, a Shi'ite Islamist who is negotiating to try to stay in power for a third term after an inconclusive parliamentary election in April, is to blame for galvanizing the insurgency by excluding Sunnis from power. Kurdish leaders have also called for Maliki to step down to create a more inclusive government in Baghdad.

The Kurds have long dreamed of their own independent state, an aspiration that has angered Maliki, who has frequently clashed with the non-Arabs over budgets, land and oil.

In July, the Kurdish political bloc ended participation in Iraq's national government in protest against Maliki's accusation that Kurds were allowing "terrorists" to stay in Arbil, capital of their semi-autonomous region.

SEEKING WEAPONS

In another move certain to infuriate the Baghdad government, the Kurdish region is pressing Washington for sophisticated weapons it says Kurdish fighters need to push back the Islamist militants, Kurdish and U.S. officials said.

Sunday's withdrawal may help them press their case.

Maliki needs the Kurds, who gained experience fighting Saddam Hussein's forces, to help defend his country from the Islamic State, whose leader Abu Bakr al-Baghdadi has a $10 million U.S. bounty on his head.

The Islamic State's ambitions have alarmed other Arab states who fear their success could embolden militants region-wide.

Islamic State fighters were among militants who clashed with Lebanese forces overnight in and around Lebanon's border town of Arsal. At least 10 Lebanese soldiers and an unknown number of militants and civilians died in the fighting, security officials said.

There has been no indication so far whether the advance in northern Iraq and the fighting in Lebanon were coordinated.

On Friday, Saudi Arabia's King Abdullah urged regional leaders and religious scholars to prevent Islam from being hijacked by militants.

Sunni Saudi Arabia considers the Islamic State a terrorist organization, but Maliki and other Iraqi Shi'ites blame it for sustaining Sunni militancy by backing other sectarian groups. (Writing by Michael Georgy; Editing by Peter Graff and Tom Heneghan)