Robert Wright on culture, politics and world affairs.

Can somebody remind me how my tax dollars wound up going to pay 12-year-old Somali boys to walk around with rifles and, when circumstances seem to warrant it, kill people?

Oh, wait, it’s all coming back — which is good, because the lessons go well beyond Somalia, and help explain why the war on terrorism hasn’t gone well lately.

A guy my tax dollars were devoted to killing, back in 2006, is now the guy my tax dollars are devoted to arming as he fights guys we inadvertently helped empower.

Back in 2006, President George W. Bush supported and helped finance Ethiopia’s military intervention in Somalia. The idea was to prop up a faltering Somali government and fend off an insurgent force called the Islamic Courts Union — even though observers warned that a) the I.C.U., by bringing order to long-chaotic parts of Somalia, had become more popular than the government we were backing; b) there were I.C.U. leaders who, by local Islamist standards, were moderate, so maybe we should try to work with them instead of kill them; c) backing a Christian government’s armed intervention in a Muslim country wasn’t the best way to win hearts and minds in the war on terrorism, and indeed might weaken those moderates within the I.C.U. and empower their radical rivals.

Sure enough, the American-Ethiopian intervention backfired. It wound up strengthening a radical wing of the I.C.U., which, under the name al-Shabaab, became the dominant insurgent group. In retrospect, the moderates in the I.C.U. looked pretty good, and the United States helped one of them, Sharif Sheik Ahmed, become head of the government that we continued to try to resuscitate.

So a guy my tax dollars were devoted to killing, back in 2006, is now the guy my tax dollars are devoted to arming as he fights guys we inadvertently helped empower. (And his operations seem not to be going very well.)

Now, given that al-Shabaab uses 12-year-olds as soldiers, maybe it’s not surprising that our man Ahmed is using 12-year-olds as soldiers, too. Still, this isn’t our finest moment, and two morals of this sad story are particularly noteworthy.

1) Military intervention can take an essentially local Islamist movement and turn it into a threat to the United States by driving it into alliance with America’s enemies. It was after the American-Ethiopian intervention that al-Shabaab crystallized and cultivated strong ties with Al Qaeda.

2) Once we’ve thus internationalized tensions that had been largely local — once we’ve strengthened bonds between locals and Al Qaeda, and strengthened the America-versus-Islam narrative deployed by jihadist recruiters — American Muslims who for whatever reason are already unstable become vulnerable to that recruiting pitch. Only this month, two Americans were arrested as they headed to Somalia to join the international war against crusaders. (The journalist Adam Serwer has been almost alone in noting the link between the cultivation of these jihadists and the 2006 Ethiopian-American intervention.)

Does any of this sound eerily familiar? It should. Here’s why:

1) In Iraq, the jihadist group that created so much carnage — “Al Qaeda in Mesopotamia” — didn’t even exist in that form until we invaded. Before the war it wasn’t affiliated with Al Qaeda (much less called Al Qaeda) and was more anti-Jordanian government than anti-American.

2) In Afghanistan, our troop presence in rural villages is driving local leaders who resist occupation into the arms of Taliban Central, based in Pakistan. Meanwhile, our intervention in both Afghanistan and (via drone strikes) Pakistan seems to be strengthening Taliban Central’s bond to Al Qaeda. (Opinions differ over how close Al Qaeda’s relationship to the Taliban was before the Afghanistan war, but in any event our becoming their common enemy has brought a convergence of their strategic goals.)

And with both Iraq and Afghanistan, as with Somalia, our involvement in conflict helps nurture terrorists here at home. The Fort Hood shooter was outraged by both the Iraq and Afghanistan wars, and the Times Square bomber was upset by the Iraq war and the Pakistani drone attacks that are spillover from the Afghanistan war.

Terrorists like these create exactly what Al Qaeda wants: American suspicion of American Muslims and even attacks on American mosques. Needless to say, this kind of domestic atmosphere can create more homegrown terrorists, which can further intensify the atmosphere, which can create more homegrown terrorists and so on. This is Osama bin Laden’s dream, and our foreign policy seems almost designed to make it a reality.

Shifting course won’t be easy. It’s not as if withdrawing from Afghanistan would restore calm, and it’s not as if 12-year-old Somali killers would join a Boy Scout troop if only we’d quit paying for their rifles.

But humanitarian problems like these are the whole world’s burden and should be handled — in cases where they can be handled — by the international community. We should contribute our fair share, yes, but going further than that wouldn’t make sense even if we knew how to do so successfully—which, manifestly, we don’t.

It’s tempting to defend President Obama’s persistence in foreign policy fiascos by saying that he inherited them from George Bush and can’t wind them down overnight. But in some ways Obama is out-Bushing Bush. He’s radically increased the use of drone strikes and is expanding “covert” military operations that can wind up backfiring much the way America’s support for the Ethiopian intervention in Somalia backfired. In some of these cases he is taking radical Muslims with essentially local grievances and turning them into America’s enemies.

And he’s failing to heed the most fundamental lesson of Somalia and for that matter Afghanistan and Iraq: No matter how bad things are, trying to make them better can always make them worse.