Hard to put into one simple answer. But I think it happened mainly because of greed of American big oil companies taking oil from foreign lands because it's easier than producing our own energy here in America, and foreign countries have different views on many things that in our country, many abuse. This causes many foreigners to view Americans in a very undesirable way, or despise us. Very sad to be labeled this way, but that's the facts.
The simple short answer is, the U.S. trained and gave weapons to the afghan people, including Osama Bin Laden in the 1980s to fight the Russians(our enemy at the time). Bin Laden and his terrorist organization attacked the United States on September 11th.