On a visit to about 600 U.S. troops on this remote base near Jalalabad in eastern Afghanistan, Carter said 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 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
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 "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.
An Air Force lieutenant asked Carter whether the U.S. intends to maintain permanent military bases in Afghanistan, such as those in Japan and Germany.
"I don't see it on that scale, because I don't see it to be the need here," Carter replied. "But I do see entering a security partnership, yes. This is an important part of the world to have friends and a foothold in."
Washington provides more than $4.1 billion a year in aid to the Afghan military.
Mohammed Massoon Stanekzai, the acting Afghan defense minister, said the country needs better equipment, intelligence and other support to guard against insurgent attacks.
The Pentagon plans to deliver eight A-29 Super Tucano attack aircraft to the Afghans early next year. It will be the first time the Afghans have their own fixed-wing aircraft to provide close-air support for their forces.
"Making an Afghan air force is not going to happen overnight," Stanekzai said after meeting with Carter. "We have a long way to go."
Follow @wjhenn for military and defense info.