Defense Secretary Ashton Carter (Alex Wong/Getty Images)

Defense Secretary Ashton B. Carter predicted Friday more tough fighting ahead in Afghanistan as the United States seeks to help local forces beat back a surge in Taliban attacks and contain an emerging threat from militants linked to the Islamic State.

Carter touched down at Operating Base Fenty in Afghanistan’s Nangahar province — along the Pakistan border east of Kabul — where an array of armed groups pose a major test to Afghan forces as the bulk of foreign troops withdraw.

Violence has surged across Afghanistan this fall amid a power struggle among Taliban leaders.

In October, Taliban fighters overran the northern city of Kunduz before being driven back. The group also mounted sustained attacks in the southern Kandahar and western Helmand provinces, straining morale within struggling Afghan forces despite a decade of foreign training.

“I expect in the next year for the fighting to be hard, too,” Carter said following talks at the base with acting Afghan Defense Minister Mohammed Masoom Stanekzai.

It was Carter’s first visit since President Obama announced in October that the United States would keep a force of 5,500 U.S. troops in Afghanistan into 2017, abandoning his earlier ambition to withdraw all U.S. troops before he leaves office.

The Pentagon is also slowing the pace of troop reductions next year, a recognition of the ongoing reliance of Afghan troops on foreign military power, and of the continued insurgent threat that a 14-year U.S. and NATO operation has been unable to extinguish.

According to a Pentagon report released this month, insurgents are improving their ability to “find and exploit” Afghan government vulnerabilities.

The increasingly tenuous situation in Afghanistan is a reminder that Obama’s hopes of ending the insurgent wars begun under his predecessor have not played out as planned. In addition to extending its presence in Afghanistan, the United States has returned to combat operations in Iraq and is expanding its military role in Syria.

Under current plans, the U.S. military will remain at a major air base in Bagram, north of Kabul, along with several other facilities throughout Afghanistan. While much of the future effort will focused on training and advising Afghan forces, the Obama administration has also laid plans for substantial counterterrorism operations focused on al-Qaeda.

“This year was all about trying to show control” by militant factions amid the exit of NATO forces, said Gen. John Campbell, the U.S. and NATO military commander in Afghanistan.

Speaking to reporters, Stanekzai said Afghanistan would require “long-term support and help of international friends” to sustain it. According to U.S. statistics, casualties among Afghan security forces increased by nearly 30 percent during the first 11 months of 2015.

While Carter renewed promises Friday of long-term support to Afghanistan, it is the next president who will decide how long U.S. troops will stay. U.S. lawmakers will have control over U.S. military aid to Afghanistan, which can pay for only a small share of its annual security costs. The U.S. contribution now stands around $4 billion a year.

Stankekzai added that military action was only one part of the government response needed to combat groups such as the Islamic State, in addition to measures related to the economy, employment and regional diplomacy.

Fighters from the Islamic State, also known as Daesh, first entered the province last year, making their barbaric mark by forcing a group of village men to sit on explosives and then detonating them. Since then, the black-clad fighters have gained control of several districts, where they have closed schools, declared the right to take widows and unmarried girls, and meted out regular brutal punishments to enforce sharia law.

Until now, most Islamic State-affiliated forces in Nangahar have been Afghan Taliban defectors, Pakistan-based militants and Islamist fighters from Uzbekistan.

Three days ago, in a sign of its growing reach, the Islamic State launched a radio broadcast in Nangahar, called “The Voice of the Caliphate,” which urges young men to join its holy war and issues propaganda against the government.

Residents have said they fear it will attract jobless young men. Afghan officials have not been able to locate its source, but provincial officials said it was being broadcast from across the border, presumably in the tribal regions of Pakistan.

“Nangahar is the region that most distresses us now,” Gen. Dawlat Waziri, senior spokesman for the Afghan Ministry of Defense, said in an interview Thursday. He said Afghan forces have defeated the Islamic State in several other provinces and are now aggressively fighting them in four districts of Nangahar, where they have killed between 300 and 400 militants in recent months.

But after fleeing to the mountains, he said, the militants “reemerged” and are now fighting to take three districts again, in some cases in alliance with Taliban fighters and in other cases against them. The Islamic State forces “have money,” Waziri said. “They buy Taliban commanders, and weaker Taliban groups switch sides.”

Constable reported from Kabul.