NATO will hold a ceremony in Kabul later Sunday formally ending its war in Afghanistan, officials said, after 13 years of conflict that have left the country in the grip of worsening insurgent violence.