The short answer
The Afghan government and its international partners fought against the Taliban and allied militant groups. The main foreign forces came from the United States and its NATO allies and partners. The war was not a clean contest between two countries, because it involved shifting alliances, local militias and several armed groups.
The Afghan government and its partners
The Afghan government relied on its own army and police, which the international forces trained and supported. Foreign troops came from the United States, which led the largest share, along with the United Kingdom, Canada, Germany, France, Italy, Turkey, Poland, Australia and dozens of other countries over the years. At its peak, the ISAF mission included troops from about 50 nations.
The Taliban and allied groups
The Taliban were the main opponent. They were joined by the Haqqani network, which operated with a great deal of autonomy, and by al-Qaeda, which had a smaller presence by the later years. From around 2015, the Islamic State’s Afghan branch also carried out attacks, adding a third armed group to the conflict.
Neighboring countries
Pakistan was a key partner. Much of the foreign military’s supply moved through Pakistani routes, but Pakistan was also widely accused of giving the Taliban sanctuary across the border. Pakistan’s government denied this. Iran and Russia had their own interests in the region but did not openly deploy fighting forces in Afghanistan.
Why it was not a two-sided war
Local militias, regional commanders and tribal groups sometimes fought for or against the government at different times. Alliances could change from one district to the next. For the timeline of how these forces were organized, read the history of NATO in Afghanistan.