WASHINGTON (AP) — The imminent fall of the Islamic State's de facto capital leaves America a multitude of tasks to restore stability in the Middle East, starting with pockets of remaining IS resistance in Syria and Iraq.

Then there are the more deeply rooted problems, not fixable by guns or bombs, that allowed extremism to rise and flourish: Syria's civil war and Iraq's intractable political, religious and ethnic disputes, which turned violent again this week.

The challenge is more than the U.S. can handle alone. It likely will keep some troops in Iraq for years to come to train and advise the army, police and other members of security forces that imploded when IS fighters swept across the Syrian border and captured Mosul in June 2014.

The militants also have footholds in Afghanistan and beyond. On Monday, the Pentagon said it used drone aircraft to strike two IS training camps in Yemen, killing dozens.

Syria has been fertile ground for IS, which capitalized on the civil war to expel al-Qaida and more moderate opposition fighters from Raqqa almost four years ago, making the city the capital of its self-declared "caliphate." The Obama administration sought to stay out of the civil war even as it claimed hundreds of thousands of lives.

The Trump administration has largely stayed on the sidelines of attempts, now led by Russia and Iran, to organize local cease-fires and create so-called "de-escalation zones," with the exception of one such area near the Israeli and Jordanian borders. But it has been generally supportive of U.N.-led efforts to resurrect stalled political talks aimed at forging a transitional administration.

On the ground in Syria, the administration has redefined America's priorities to focus primarily on securing military gains and providing immediate reconstruction assistance to restore critical infrastructure and temporary governance.

Heather Nauert, the State Department spokesperson, said that once Raqqa is fully liberated the U.S. and its coalition partners will focus on helping to remove dangers posed by unexploded bombs in the area.

"Eventually, we would get to the point where we would start to remove some of the rubble, get to the point where we would get the electricity going once again, providing clean water -- the same types of things that the U.S. and coalition partners were able to do in Mosul," she said.

The collapse of IS defenses in Raqqa, after four months of fighting, does not necessarily equate to the collapse of the militant group. The U.S. military on Tuesday estimated 6,500 IS fighters remain in eastern Syria and western Iraq, many concentrated along the Euphrates River valley straddling the border. Even if they no longer control significant territory, they pose an insurgent threat in both countries and an ideological threat globally.

Col. Ryan S. Dillon, a spokesman for the U.S.-led coalition fighting IS in Syria and Iraq, told reporters at the Pentagon that Raqqa is about 90 percent freed, but more fighting will be required to fully liberate the city. As evidence of remaining risks, he said the Syrian commander of a so-called Raqqa Internal Security Force, whose task will be to keep order in the city once the last IS fighters have been ousted, was killed Monday by an improvised bomb.

Defense Secretary Jim Mattis said last week that IS is "close to being crushed." He also cautioned against assuming an easy end game, likening the problem to squeezing a tightly packed snowball.

"You can compact them and compact them, and eventually it shatters," meaning IS remnants "can show up in other places." He was speaking about four soldiers killed this month in the African nation of Niger, possibly by an IS affiliate.

Planning for some of the major attacks in Europe in recent years was traced back to Raqqa. These include the 2015 Paris attacks, which killed 130 people, and the 2016 suicide attacks on the Brussels airport and subway, which killed 32.

The breadth of the problem was underlined by Britain's chief of domestic intelligence, who said in London that the Islamist extremist threat facing his country has accelerated at an alarming pace and is worse now than at any time in his 34-year career. MI5 Director General Andrew Parker said the risk is further heightened by the possible return to Britain of people who had joined IS in Syria and Iraq.

"That threat is multi-dimensional, evolving rapidly, and operating at a scale and pace we've not seen before," he said.

In Iraq, optimism created by a series of relatively swift victories by Iraqi security forces was punctured by renewed conflict between the central government in Baghdad and the semi-autonomous Kurdish regional government, whose peshmerga militia fighters had taken control of the disputed city of Kirkuk after IS took Mosul in 2014.

The Kurds had included disputed areas, including Kirkuk, in a non-binding referendum last month in which more than 90 percent of voters favored independence. The Iraqi government, as well as Turkey and Iran, which border the land-locked Kurdish region, rejected the vote.

Baghdad has spent the last three years demanding the Kurds return Kirkuk to federal control, and appeared to be on the verge of taking military action after the referendum. Sporadic clashes broke out as Iraqi forces moved toward Kirkuk on Monday, but within hours Kurdish forces had withdrawn from the city's airport, an important military base and nearby oil fields.

___

AP Diplomatic writer Matthew Lee contributed to this report.