Pretty much what they did. Overwhelming force. That's how the justice system is supposed to work.

The problem is that these kids were "organized" after a fashion. They were muslims, discontent, and grabbed up by some radical muslim and told that massacring random americans is the way to heaven. They're very unlikely to be the only ones that believe so.

And what choice is there but to move against whatever persons and/or organizations that radicalized their "interpretation of islam". They pointed out that the muslim prophet was a mass-murdering genocidal raider, which is correct, so it's hard to argue against this point. And of course these 2 boys chose to join their prophet's ways, as opposed to denying them. It's an ingenious way for an ideology to create terror, really. You center the ideology around a figure that's described as "perfect"(/holy/enlightened/...), but in reality that figure is a mass-murdering lying cheating bastard. Then of course the vast majority of people will choose to deny that fact (because 90% of people even in the most radicalized islamic country know perfectly well there's nothing good about massacres, and if "the prophet" committed genocide, that means he and his islam is evil), leading to a society that's workable, even if periodic sudden mass-outbursts of violence are unavoidable if you expect people to live in cognitive dissonance, with the associated risk that such an outburst wins over any government in place, destroying everything
.

But any preacher can of course trivially use this to get recruits for terror acts against anyone he pleases (anyone he can realistically paint as an enemy of the ideology, which is to say anyone, if the preacher is any good). Now the vast majority of people will choose to maintain their cognitive dissonance and just add this preacher to the list of things they flat-out deny about the world, so the preacher that has just advocated genocide for 30 minutes can easily share dinner with anyone who just listened (When I first saw someone deny in his mind that a door existed to the point that he had to be restrained because he would keep "walking through it". He was hurting himself to the point that restraint + sedation was the only solution. I left that institution still firmly convinced that such people didn't exist, but after a few nights I seem to have come to terms with it).

However some people will chose to end their dissonance, usually under stress, and crucially, at this point they'll have been in the ideology for years and years, with everybody they know telling them that islam is good and great and can't be criticized. Then this "great insight" comes, that they've known about for decades too : islam works by ambushes and genocide, that's how the prophet did it, that's how muslims should do it. And at that point they will be extremely vulnerable to "suggestions" from said preacher, and of course they'll be looking to imitate what their prophet did, and they'll be looking for exactly the kind of mission that the preacher is likely to give them : ambush and kill innocents who are part of a group that "opposes" islam (and the prophet massacred muslims that he accused of allying with an enemy just the same, so no need to worry about killing a few traitor muslims).

No amount of policies can prevent psychological stress, nor by the way, would you want to do that. Stress may be the way to insanity, but it's also the way to improving yourself. Aside from that, of course you can't "end" psychological stress (though of course you can massively reduce it by providing basic needs services). But you'll never minimize it to the point the supply of terrorists dries up. And of course there's going to be points where the economy of the country is stressed, and there's an explosion in the number of candidate terrorists.

As a bonus, any society with this ideology can of course not allow "free" preachers, or any form of freedom of ideology. That would lead to mass acts of terrorism in short order (what we're about to see in Europe and America). So any society where this ideology takes root either becomes a complete monoculture or destroys the "invading" ideology, at great cost.

I bet this is how a lot of the terror ideologies work, not just islam. This seems like it's roughly the same concept as the stalinism and leninism concepts of communism (and of course the lesser ones too, with Castro, Guevara* and Chavez), or things like the Japanese ideology before WWII, and of course nazism, any such person cultus with anything less than a perfect being like Buddha or Jesus, that no rational being can really criticize any actions of (which means that Christian and Buddhist "terrorists" exist, except they do what Jesus and Buddha did, probably leading to self-sacrifice for a noble cause, because these are ideologies where people's cognitive dissonance has to deny the fact that they themselves are not as moral as their ideology). I bet this is what a "meme" virus looks like, like Hitches professed exist.

Of course negative ideologies (where the ideology is morally worse than most human minds that partake in it) like islam would be fundamentally unstable, and will destroy themselves if they don't have (realistic) enemies, or insufficient access to their enemies. But small pockets will survive even then, ready to start again, in slightly different forms. So preventing terror is the exact same thing as eradicating islam itself, problem is that of course you're never going to be able to do that without attacking individuals.

* Guevara is a perfect example. He's a hero of commusnism, but it is well documented he randomly killed people for fun when they can't defend themselves. And that's not all he's reputed to do either.