BAGHDAD — Iraqi and Kurdish forces recaptured Iraq’s largest dam from Islamic militants Monday following dozens of U.S. airstrikes, President Obama said, in the first major defeat for the extremists since they swept across the country this summer.

Militants from the Islamic State group had seized the Mosul Dam on Aug. 7, giving them access and control of enormous power and water reserves and threatening to deny those resources to much of Iraq.

Iraqi forces suffered a string of humiliating defeats at the hands of the Islamic State as the extremists took over large parts of northern and western Iraq and sent religious minorities fleeing.

The militants’ battlefield victories brought U.S. forces back into the conflict for the first time since it withdrew its troops in 2011 and reflected the growing international concern about the Sunni extremist group. Washington launched attacks from its warplanes and drones on Aug. 8.

Obama called recapturing the dam by Iraqi and Kurdish forces a “major step forward” in the battle against Islamic State militants.

Had the dam been breached, it could have had catastrophic consequences and endangered U.S. Embassy personnel in Baghdad, Obama said at the White House. He said the U.S. is urgently providing arms and assistance to Iraqi security forces as well as Kurdish fighters fighting the extremists.

“We’ve got a national security interest in making sure our people are protected and in making sure that a savage group that seems willing to slaughter people for no rhyme or reason other than they have not kowtowed — that a group like that is contained, because ultimately it can pose a threat to us,” Obama told reporters.

He also urged the badly fractured and largely dysfunctional Iraqi government to move quickly to forge a united front. He noted last week’s decision by Nouri al-Maliki to step down as Iraq’s prime minister, a move that raised hopes a new government could roll back Iraq’s powerful Sunni insurgency and prevent the country from splitting apart.

“They’ve got to get this done because the wolf’s at the door,” Obama said.

There were conflicting statements throughout the day from the Kurdish commanders, the Iraqi military in Baghdad, the Pentagon and the militants of the Islamic State group over who was in control of the strategic 2.1-mile dam that spans the Tigris River. Completed in 1986 under Saddam Hussein, it includes a sprawling complex with power generators, offices and employee housing. The southern end is mostly reserved for housing and offices.

Before Obama spoke, Kurdish forces spokesman Halgurd Hekmat said the peshmerga regained full control of the dam and its surrounding facilities following two days of fierce clashes. But Iraq’s Defense Ministry said security forces only “liberated a large part of the Mosul Dam” with the help of U.S. airstrikes, adding that forces had not freed the entire complex.

Iraqi army spokesman Lt. Gen. Qassim al-Moussawi said at least 170 bombs have been dismantled around the dam but many more remain. He added that militants fled to areas near the south of the complex, hiding in homes and offices on the premises.

The Islamic State group denied it had lost control of the facility, saying on a website frequently used by the militants that the Iraqi government claim was a “mere propaganda war.”

The U.S. Central Command said it carried out 15 airstrikes near the dam Monday with fighter jets, bombers and drones. There were 25 U.S. airstrikes on Saturday and Sunday, it said.

The Obama administration has also agreed to supply peshmerga forces with light weapons and ammunition, as have the French.

The moves may provide Iraqi forces with a significant morale boost as they try to retake territory overrun by the Islamic State this summer.

Some 1.5 million people have been displaced by fighting in Iraq since the Islamic State’s rapid advance began in June. The scale of the humanitarian crisis prompted the U.N. to declare its highest level of emergency lasts week.

As he returned from a trip to South Korea, the pope was asked if he approved of the unilateral U.S. airstrikes on the militants who have forced minority Christians and others to either convert to Islam or flee their homes.

“In these cases, where there is an unjust aggression, I can only say that it is licit to stop the unjust aggressor,” Francis said. “I underscore the verb ‘stop.’ I’m not saying ‘bomb’ or ‘make war,’ just ‘stop.’ And the means that can be used to stop them must be evaluated.”

But, he said, in history, such “excuses” to stop an unjust aggression have been used by world powers to justify a “war of conquest” in which an entire people have been taken over.

“One nation alone cannot judge how you stop this, how you stop an unjust aggressor,” he said, apparently referring to the United States. “After World War II, the idea of the United Nations came about: It’s there that you must discuss ‘Is there an unjust aggression? It seems so. How should we stop it?’ Just this. Nothing more.”

His comments were significant because the Vatican has vehemently opposed any military intervention in recent years, with St. John Paul II actively trying to head off the Iraq war and Francis himself staging a global prayer and fast for peace when the U.S. was threatening airstrikes on Syria last year.

But the Vatican has been increasingly showing support for military intervention in Iraq, given that Christians are being directly targeted because of their faith and that Christian communities which have existed for 2,000 years have been emptied as a result of the extremists’ onslaught.

Francis also said he and his advisers were considering whether he might go to northern Iraq himself to show solidarity with persecuted Christians. But he said he was holding off for now on a decision.