KABUL, Afghanistan — U.S. Army Gen. Austin Scott Miller assumed command of the 41-nation NATO mission in Afghanistan in a handover ceremony on Sunday.

Miller took over from Gen. John Nicholson, who held the post for more than two years, at a ceremony at NATO headquarters in Kabul attended by senior Afghan officials and foreign ambassadors.

The handover comes as Afghan forces are struggling to contain a resurgent Taliban and an increasingly powerful Islamic State affiliate. The Taliban control several districts across Afghanistan, and both groups have launched a relentless wave of attacks in recent months.

"The world recognizes Afghanistan cannot be a safe haven for terrorism, the world recognizes that we cannot fail. I know this has been a long fight, and it has been generations for us, for the Afghan people," said Miller, who most recently led the Joint Special Operations Command.

Nicholson called on the Taliban to accept the government’s offer of a cease-fire and renewed peace negotiations, saying “you don’t need to keep killing your fellow Afghans.”

Outgoing U.S. Army Gen. John Nicholson, left, and incoming U.S. Army Gen. Austin Miller, second from left, prepare for the change of command ceremony at Resolute Support headquarters in Kabul, Afghanistan, Sunday, Sept. 2, 2018. Miller has assumed command of the 41-nation NATO mission in Afghanistan following a handover ceremony. (Massoud Hossaini/AP)
Outgoing U.S. Army Gen. John Nicholson, left, and incoming U.S. Army Gen. Austin Miller, second from left, prepare for the change of command ceremony at Resolute Support headquarters in Kabul, Afghanistan, Sunday, Sept. 2, 2018. Miller has assumed command of the 41-nation NATO mission in Afghanistan following a handover ceremony. (Massoud Hossaini/AP)

The nearly 17-year-old NATO mission began with the U.S.-led invasion that toppled the Taliban after the Sept. 11 attacks. The U.S. and NATO formally ended their combat mission in 2014 but still routinely come to the aid of Afghan forces.

Afghanistan’s national security adviser, Hamdullah Mohib, acknowledged the setbacks, saying “we have a bloody nose, but we are not defeated.”