OPERATING BASE FENTY, Afghanistan - Defense Secretary Ash Carter warned Friday of the threat of deteriorating security in Afghanistan from a resurgent Taliban and a growing number of Islamic State fighters.

On a visit to about 600 U.S. troops on this remote base near Jalalabad in eastern Afghanistan, Carter said the Islamic State has created "little nests . . . around the world, including here in Afghanistan."

U.S. commanders estimate that the Sunni Muslim extremist group has 1,000 to 3,000 fighters here. Many apparently are former Taliban members who shifted allegiance.

The warning comes after a year that saw the Afghan army and police suffer more than 5,000 casualties as U.S.-led coalition troops steadily withdrew from the battlefield and Taliban attacks surged.

In September, Taliban fighters overran the northern town of Kunduz, the first urban area they had captured since the U.S.-led invasion in 2001.

Government forces later recaptured the city, but the battles revealed weaknesses despite tens of billions of dollars of U.S. aid and training over the last 14 years.

"The Taliban's advances in some parts of the country, even if only temporary, underscores that this is a tough fight and it's far from over," Carter said.

"It's also a dynamic fight, and as groups like [Islamic State] emerge on the battlefield, or al-Qaeda seeks to reestablish a safe haven, we must be prepared to deter their growth and counter the threats they pose," he added.

Carter arrived here after stops this week in Turkey, Bahrain and Iraq, where he visited Baghdad and the northern city of Irbil. He met with troops, allies, and commanders involved in the battle against Islamic State.

A Pentagon study released this week concluded that security in Afghanistan was worsening by almost any measure. It said the Taliban leaders "likely will try to build momentum from their countrywide attack strategy" next year.

The U.S.-led invasion in late 2001 was aimed at eradicating a sanctuary for al-Qaeda, which had launched the Sept. 11 attacks, and ousting the Taliban from power in Kabul. It proved relatively easy to topple the Taliban, but difficult to pacify or unify a poverty-stricken country ruled by warlords.

Although international military forces had planned to end their combat mission last December, about 17,000 coalition troops remain in the country. The total includes about 9,800 U.S. troops.

Unlike in Iraq, U.S. special operations troops still accompany Afghan forces on combat missions, while American fighter jets and drones provide air support to ground troops. One such U.S. air attack mistakenly hit an international hospital in Kunduz in October, killing 30 medical staffers and patients.

"We're looking hard at the lessons of this very tough fighting season of '15, and we'll make adjustments off that and get ready again for '16," Gen. John Campbell, the U.S. commander in Afghanistan, told reporters traveling with Carter.

Carter and Campbell said the United States will need to assist the Afghan government for years to come.