They didn't "get lucky." They did dry runs before the real thing to see what they could get away with. It was a well thought out plan that worked on four different planes.
America taking the fight to the Taliban and Al Qaeda in Afghanistan resulted in weakening those organizations. Being proactive instead of sitting back and allowing them to flourish might have hindered them from feeling out other weaknesses in our system and investing in the next terror attack.
That said, I don't think all of America's defense spending has been spent wisely. We do a lot of wasteful spending (on Defense among other things).
And look where we are now. American intervention in the Middle East led to rise of the Islamic State, which is worse than Al-Qaeda by just about any measure you'd like to use.
It's as if smashing foreign countries and killing thousands of people in the name of fighting terrorism doesn't work.