The smoke from mortar and rocket attacks rises from the mountains of Dangam in the remote eastern border region of Afghanistan as Talban insurgents battle government forces in a bid to establish a permanent presence now that the American soldiers who led the fight here for more than a decade have left.

Heavy fighting has been raging for almost three weeks, with wave after wave of Taliban militants assaulting this picturesque but poverty-stricken district of Kunar province just four kilometers (2.5 miles) from the border with Pakistan, officials and residents said.

The U.S.-led international effort to rid Afghanistan of the Taliban officially shifts from a combat to a training band support mission Wednesday, with Afghan forces assuming full responsibility for security nationwide on New Year's Day. A residual force of 10,800 Americans and almost 3,000 NATO soldiers will remain, under the banner of a new mission called Resolute Support.

Over the last 18 months, U.S. and NATO forces have been closing their bases across the country, taking their battlefield prowess, air support and medical evacuation assets with them.

The war is meanwhile creeping into urban and residential areas, putting ordinary people at greater risk. Civilian casualties look set to hit 10,000 in 2014, the highest yearly total of dead and wounded since the U.N. began keeping records in 2008. More than 75 percent of the deaths and injuries are caused by Taliban attacks, according to the U.N.

There are few places where Afghan forces have been tested as ferociously as in Dangam, a forested valley where life has changed little for centuries.

The fighting began when local residents decided they had had enough of the Taliban, who had set up a "shadow" administration and were attempting to take control of the valley, according to Gen. Mohammad Zaman Waziri, Afghan army corps commander for eastern Afghanistan.

The Afghan army came to help, he said, and fighting has been going on ever since.

Up to 550 families have been forced from their homes, and more than 40 houses have been destroyed, Kunar governor Sheja-ul Mulk Jalala said. Tribal elder Haji Muzamel said another 800 families have been pinned down by the fighting.

"The terrorists have very important goals in Dangam, such as establishing permanent bases or transferring their bases from the other side of the border, crushing the local people's uprising and of course creating problems for Afghan security forces," said Haseb Sediqi, spokesman for the National Security Directorate intelligence agency.

Officials said that since early December more than 1,000 heavily armed insurgents have turned up here, including members of the Pakistani Taliban, or TTP, and Lashkar-e-Taiba, the group responsible for the attacks on the Indian city of Mumbai in 2008 in which more than 160 people were killed.

The TTP said it was behind the attack this month on a school in Peshawar, in northern Pakistan, in which more than 140 people were killed, most of them children. It is not unusual for Pakistani fighters — usually referred to by Afghan officials as simply "foreigners" — to fight alongside the Afghan Taliban.

The Peshawar attack was widely seen as a watershed moment that could help dissipate the long-held mistrust between the neighboring nations as they recognize the need to deal with insurgent groups on both sides of the border.

In recent weeks, Afghan, Pakistani and coalition military leaders have shuttled back and forth between Kabul and Islamabad to discuss cooperation at all levels, including military and intelligence, officials have said. The counter-terrorism component of the Americans' remit in Afghanistan, expanded by President Barack Obama, will allow U.S. troops to engage in operations against the Taliban, as well as al-Qaeda, and provide the Afghans with battlefield and air support.

In Dangam, officials said the international coalition has not yet been called upon to help repel the Taliban attacks.

Sartaj Aziz, a senior adviser to Pakistani Prime Minister Nawaz Sharif, praised the Afghan efforts in Kunar, telling local television: "It was a good thing on the part of (the) Afghan government and will help bring peace to the nation."

Afghanistan and Pakistan share a 2,250-kilometer (1,400-mile) border and militants from both sides routinely launch cross-border attacks. This has long strained relations, with the two countries accusing one another of offering safe haven to terrorists.

But Afghan President Ashraf Ghani, who took office in September, has said he will never allow militants to enjoy safe haven in Afghanistan. And Pakistan's Sharif has said the days of distinguishing between "good" and "bad" insurgents are over. Analysts have long accused Pakistan of battling its own insurgents while tolerating or even working with the Afghan Taliban to destabilize its neighbor in order to prevent regional rival India from expanding its influence in South Asia.

The fighting in Dangam will test those pledges, and the mettle of Afghanistan's troops. Thus far they are holding the line, having lost just six soldiers in three weeks of fighting, with another 20 wounded, Waziri said. But the columns of gray smoke and the explosions echoing across the forbidding hills indicate the battle is far from over.

___

Associated Press writer Zarar Khan in Islamabad contributed to this story.

___

Follow Lynne O'Donnell on Twitter at https://twitter.com/lynnekodonnell