Why did the United States choose to go to war in Afghanistan?

The United States chose to go to war in Afghanistan in response to the 9/11 terrorist attacks carried out by the extremist group Al-Qaeda, which was being harbored and supported by the Taliban regime in Afghanistan. The goal of the war was to dismantle Al-Qaeda, remove the Taliban from power, and prevent Afghanistan from being used as a safe haven for terrorist activities that could threaten the United States and its allies.