KABUL, Afghanistan - The 13-year NATO combat mission in Afghanistan formally ended Sunday with a ceremonial retirement of its green flag and a pledge by top officials of the U.S.-led coalition to remain reliable partners in Afghanistan's unfinished war against the Taliban and other militant groups.

Scores of Afghan and foreign officials gathered to witness the symbolic shift to a new, much smaller NATO assistance and training mission. The event was held in a basketball gym inside NATO headquarters here in the Afghan capital and accompanied by a brass band and color guard.

"Our commitment to Afghanistan endures. . . . We are not walking away," promised Gen. John F. Campbell, the U.S. commander of the outgoing International Security Assistance Force combat mission. He will lead the new NATO support mission, which technically begins at midnight Dec. 31.

Campbell and other Western officials stressed that their chief function under the new mission, named Resolute Support, will be to advise, train, and assist Afghan security forces. They said, however, that a separate "non-NATO" contingent of U.S. forces will participate in force protection, logistical support, and counterterrorism activities.

The Taliban responded to the transition event with glee. In a lengthy statement Sunday night, the insurgent group gloated at the final departure of a "haughty" superpower that "thought it had already won the war and that the Mujaheddin would never . . . think of putting up a fight."

The statement said the NATO withdrawal was proof that "the infidel powers who thought they would turn Afghanistan into their strategic colony" had been "pushed to the brink of defeat."

The total number of international troops here, which peaked in 2009 at about 142,000, has gradually shrunk to about 17,000. Under Resolute Support, officials said, 12,500 to 13,500 NATO forces will remain in 2015, including thousands of American troops. Twenty-eight NATO allies and 14 partner nations will contribute in different ways, the alliance said. Officials said about 5,500 U.S. forces will be part of the second contingent, which will be based in Kabul.

Both Western and Afghan officials at the event described the shift in upbeat terms. They praised the dedication and bravery of Afghan security forces, now numbering about 350,000, and predicted that the Afghans will continue to wage a strong fight against Taliban and al-Qaeda insurgents on their own.

Gen. Hans-Lothar Domröse, a senior NATO official based in Brussels, declared that Afghan forces have shown the "ability, will and confidence to defeat the enemy."

But the withdrawal of international combat support comes at an especially tense time for Afghanistan, with the Taliban aggressively testing the will of the new government amid the drawdown. Since early November, Taliban forces have waged an unprecedented terror campaign in the capital and made steady inroads in several provinces, such as Helmand, where U.S. and British forces once held sway.

At the transition ceremony Sunday, the only Afghan official to speak was the civilian national security adviser, Hanif Atmar. He expressed gratitude for the sacrifices made by NATO forces. About 3,500 international troops have been killed and tens of thousands wounded since 2001.