Last month, four American soldiers died in an ambush in Niger, a country few college graduates can locate on a map. Media figures either couldn’t pronounce the name properly or confused it with Nigeria. Inattentive members of Congress expressed surprise at our presence in the country.

But our troops are in Africa and, if our leaders are wise, we’ll maintain our commitment. It’s a strategic frontier where global crises converge, from the centuries-old struggle between Islam and Christianity, through mass migration, to China’s resource-grabbing neocolonialism.

To cover that vast space — Niger alone is twice California’s size — we deploy a mere 4,000 to 6,000 service members to the entire continent, depending on the missions of the moment. Our African engagement is what the military terms an “economy of force” effort, doing a great deal with very little. But the stakes are enormous.

Jihad’s African comeback

Throughout the post-World War II period, an even-smaller US military presence concentrated on training African forces to fight more effectively, to behave professionally and not to overthrow their governments (our success was mixed). But beginning in the late 1970s and accelerating in the 1980s, the world suffered the resurgence of blood-red jihad, striking Africa from Algeria to Somalia. At first, we deluded ourselves that we had few interests outside of a handful of major African countries. We failed catastrophically to recognize the dynamism and the imperial reach of jihadi fanatics.

On 9/11, we started to get the message.

But we also got much wrong. Administration after administration either fled Africa (as did Bill Clinton), or focused on humanitarian aid (as George W. Bush did nobly) or toppled secular tyrants without a follow-up plan (as Barack Obama did with Khaddafy in Libya).

Security got short-changed. Although our military established the US Africa Command (AFRICOM) a decade ago, we headquartered it in Stuttgart, Germany, the equivalent of parking the NYPD commissioner in Portland, Ore. Even now, we have only one acknowledged base on the continent, Camp Lemonnier in Djibouti, on the Horn of Africa, and a few quiet outposts elsewhere.

In this age of militarized, hypermobile terrorism, we have to go where our enemies go

In this decade, the wildfire spread of jihad across the northern third of Africa finally brought us to the aid of besieged local governments and the French — who had been doing their best to hold the line. But it took a string of terrorist successes to get us moving.

Al-Shabaab proved resilient in Somalia. Boko Haram slaughtered and kidnapped its way across northern Nigeria. Islamists seized Timbuktu and threatened the rest of Mali. Fanaticism gnawed at Chad, Niger and their neighbors. Meanwhile, the Obama administration’s bumbling in Libya opened up a major refuge for jihadis, even as the Islamic State’s self-declared caliphate died in the Middle East.

In this age of militarized, hypermobile terrorism, we have to go where our enemies go. We’re in Africa, above all, to keep our homeland safe. Our thin presence consists of special operators, drone support, intelligence personnel, military-assistance teams and vital-but-often-forgotten defense attachés, performing missions that range from clandestine terrorist hunting to training local forces. Mostly, we conduct small-group missions “far from the flagpole,” often under high-risk circumstances. Most of our troops aren’t there to fight, but, as in Niger, the fight sometimes comes to them.

The loss of four Special Forces personnel in Niger resulted from an ambush on unfamiliar territory and, quite possibly, a betrayal (always a concern in any counterinsurgency effort). Sgt. La David Johnson, one of the four fatal casualties, apparently had been taken alive, tortured, executed and dismembered. An investigation is underway, but that’s the environment in which we have to operate. There isn’t a no-risk response to global jihad.

So that mission-gone-awry in Niger surprised no one with military experience. Our special operators are superb, but they’re only human. Sometimes the local intelligence is faulty or the drones are grounded by sandstorms. Sometimes the leader on-site makes the wrong call. Sometimes the enemy, working his own turf, gains the advantage. But you can’t defeat a tenacious, committed foe if your priority is avoiding the enemy.

Clash of religious civilizations

Jihad is so fierce in northern and north-central Africa because it has such deep and troubled roots. For all the attention paid to the confrontation between Christian Europe and Middle Eastern Islam over the centuries, that struggle never fully transcended great-power ambitions. But the fracture line crossing Africa where the desert passes into the savannah reveals a true conflict of faiths. Tribes and ethnicity matter, but religion drives the butchery.

Just where the vegetation thickens, Islam stopped a millennium ago. Islam couldn’t lastingly penetrate the rain forest. For all of its triumphs elsewhere, the faith of Muhammad failed to convert the forest dwellers, who clung to local beliefs. Yet, centuries later, Christianity took root where Islam had failed.

When I did my last project in Africa for the Marine Corps a decade ago, I ranged from Ghana to Senegal. Up-country in Ghana, observing Christianity rubbing shoulders comfortably with folk-religion, it struck me that the forest, everywhere, is the realm of magic (our fairy tales take place in the woods, where mundane rules are suspended).

The Sunni Islam that charged out of the deserts shuns magic and couldn’t make peace with the forest. Christianity, though, was a twofer, rich in miracles: Jesus raises the dead, heals lepers, walks on water, produces wine from water and rises from the grave. He’s the ultimate shaman. In Sub-Saharan Africa, Islam was a cultural invader, but Christianity fit the local psychology (Muslims were also history’s greatest slave-traders of black Africans, which didn’t help).

Now a bitter, zealous strain of Islam is back on the march. Many African Muslim congregations along the fault line have lived in relative peace with Christian neighbors for centuries. Some western African schools of Islam — notably in Senegal, but also in Timbuktu and elsewhere in the Sahel — developed rich traditions of Islamic learning. When oil-rich Saudi emissaries tried to inflict their fundamentalist, theologically backward Wahhabi cult on local societies, Muslim scholars rebuffed the proselytizers, dismissing the Saudis’ primitive beliefs. But jihadi terrorists don’t debate or bribe. They slaughter.

As in the Middle East, jihad in Africa kills more Muslims than it does Christians.

On their side of the great divide, indigenous Muslim communities struggle to hold onto treasured identities as blood-drunk zealots pursue a barbaric vision.

A continent’s future . . .

Anyone who has spent even a little time in Africa comes away heartbroken over the setbacks, the governments that turned on their own people and the appalling waste of human capital. Yet, you also feel hope. Progress is being made, if not as swiftly as wanted. And the deck was stacked. When Ghana gained independence a half-century ago, the new state counted four university graduates among its population. Most states suffer from arbitrary, European-drawn borders. The looting of the continent’s vast natural resources didn’t end with colonialism, but accelerated. China’s brutal pursuit of raw materials and influence creates ecological and human wastelands, while Beijing’s bribery and gangland loans to local elites sets back the rule of law and cripples development. Just on Friday, at the continent’s edge, terrorists slaughtered 305 worshippers in an Egyptian mosque.

On the other hand, Zimbabwe appears determined to right itself. Ghana has never been better governed. Senegal resists jihad. Elections slowly grow cleaner and, strongman by strongman, the continent’s corrupt old guard is falling. Africa makes you an optimistic pessimist.

But the continent can only progress if there’s peace. Jihad has brought chaos and misery to more than a dozen fragile states. Our presence is a shoestring investment to help the continent save itself. The potential strategic return is all but immeasurable.

We need to worry less about “mission creep” and more about jihadi leaps across continents and oceans. West Africa and the Sahel are closer to North America and Europe than Afghanistan. Investing in local security — in stability, human rights and self-defense — is a great deal more economical than coping with another 9/11.

The question shouldn’t be “Why are we in Africa?” but “Should we do more?”