The reason why the United States and its allies invaded Afghanistan was to oust the Taliban regime. This government was the direct sponsor behind the 9/11 attacks and harbored Al Qaeda training camps.
An entire summary of the invasion can be found here:
http://en.wikipedia.org/wiki/U.S._in...of_Afghanistan
The American troops in Afghanistan will leave when they are asked by the Afghan government, headed by President Hamid Karzai.
I also have friends who are serving honorably in Iraq and defending that nation from a vicious Al Qaeda insurgency.