MADRID — Terrorists following the lines laid out for them by the so-called Islamic State are setting their sights on Spain. And while there may be many reasons, one is obvious: Spain, at the urging of Washington, is being turned into a strategic base in the war to contain and eventually cut out the metastasized jihad that has spread across the Mediterranean basin. With little fanfare, a base near the town of Morón has been turned into a critical logistics and communication center for operations throughout the region. And, thus, a country that was once a transit point for terrorists is becoming their target.

This week three Islamist were arrested in Madrid allegedly planning an attack there, and a statement by Ignacio Cosidó, Director General of Police, put the plot in perspective: “The majority of the operations in recent months were about networks devoted to the identification, recruiting and indoctrination of people to be sent to conflict zones, but these three had demonstrated clear intention to attack.”

What you need to know about all this is that Europe and Africa, Spain and Morocco, virtually touch each other at the Strait of Gibraltar, although its never entirely clear if they are kissing or biting. And, most likely, relations wouldn’t be as good as they are, were it not for the role of the Washington as go-between. A U.S. intelligence briefing document sums up ties south of the Strait: “Morocco and the United States have a long history of closed relations. The U.S. military trains with the Moroccan military on a regular basis.” While Spain, of course, is a member of NATO.

The recurring problem is that so much is so close together. The Spanish cities of Ceuta and Melilla are embedded in the North African coast, with Morocco all around them and Algeria only 70 kilometers from the latter. For those who can make it over or through the fence, Spain has become the natural entry point to Europe from Africa, and that in addition to the fact that Andalusia, in continental Spain, was a historical enclave of Islam. (Yes, the Muslims and Jews were expelled in 1492, but people in this part of the world have long memories.)

Only a few months ago the Soldiers of the Algerian Caliphate (an ISIS franchise) promised to attack the country and threatened to not stop until they had “reached al-Andalus.”

The new generations of Spaniards tend to regard these daily threats with bored indifference. They were educated to the idea of integrating what once were called “the moors”; they were witnesses to the policy of “visas for all” pushed by the administration of former Prime Minister José Luis Rodríguez Zapatero. Yet this tolerance is being turned to anger in the Islamist ghettoes and barrios, which appear every week in the newspapers.

One of the latest was the marginalized barrio of El Saladillo, in Algeciras near Gibraltar, where Ayoub el-Khazzani made his home. You might remember him from last August. He was the man who allegedly tried to slaughter travelers on the high-speed train between Brussels and Paris before some brave Americans got in his way.

Four days after the frustrated terrorist attempt on the Thalys train, a joint operation of the Spanish and Moroccan police took apart an Islamist cell in Madrid and various Moroccan cities. Fourteen people were arrested who allegedly recruited new terrorists for the Islamic State. In September, an 18-year-old Moroccan woman was picked up in Gandía, Valencia, when she was preparing to travel to Syria to join ISIS. Her posts on social media tended to end, none too subtly, “Terrorism is a duty.”

Ceuta and Melilla, on the southern side of the Med, are the two European cities that have sent the greatest number of affiliates to ISIS, according to a recent report by AICS, a major private intelligence and security firm in Spain. The experts believe that these cities are not terrorist targets, but logistical and strategic bases for their operations in Europe.

Moroccan intelligence warned Spain this summer of the alarming number of “returnees” (jihadists coming back from the battlefields of Syrian or Iraq), trying to cross the border and enter Europe. It’s estimated some 3,000 such jihadists are living in northern Morocco.

Presumably, the United States would rather see these folks stopped in Old Spain than in New York. So Washington has chosen the military base Morón de la Frontera near Seville (in Andalusia) as a nerve center in the fight against jihadists, a commitment reinforced when Secretary of State John Kerry visited Spain in October.

After the September 2012 attack on the temporary U.S. diplomatic mission and nearby CIA base in Benghazi, Libya, which killed four Americans including Ambassador Chris Stevens, a “Special Purpose Marine Air-Ground Task Force for Crisis Response” was established at Morón de la Frontera, and it has wound up with a leading role as Europe looks on with something like horror toward the threats developing in Africa.

Morón had served as an important temporary staging area during the Afghanistan and Iraq invasions early in the last decade. But in mid-June, Spain and the United signed a modification of their bilateral accord that allowed the conversion of Morón to a permanent U.S. military base able to support 2,200 Marines, 500 civilians, and 36 aircraft. The work on infrastructure is well under way. And meanwhile the United States and Spain are carrying out joint military exercises. The Spanish city of Zaragoza hosted in October the biggest NATO exercise in a decade, Trident Juncture 2015, clearly intended as a message to the Russians in Syria as well as the jihadists arrayed across North Africa and the Middle East.

Some of this buildup is a result of lessons learned (too late) from the Benghazi disaster, an oft-told tale recently highlighted by Hillary Clinton’s marathon testimony before Congress. In 2012, Washington sought desperately for a force that could deploy in time to rescue the besieged diplomats and operatives in Libya, but there was none to be had. The base at Morón reportedly will serve to help protect American embassies in the region and evacuate personnel quickly in case of a crisis, while it also has the ability to intervene in small-scale conflicts and in humanitarian disasters.

If they are looking for threatened diplomatic missions, they won’t have to go far. One early morning in September the Madrid police evacuated dozens of people from the pubs and outdoor cafés of Diego de León street when it was thought a car bomb had been placed about 50 meters from the U.S. embassy.

Fortunately, the Spanish police are well trained for this kind of thing after years fighting the Basque terrorist organization ETA. Although the bomb dogs determined this was a false alarm, the Ministry of Interior know that U.S. interests are a priority target for the Islamists.

But it’s southward toward the Mediterranean where most of the attention is focused at Morón. Brig. Gen. Norman L. Cooling told the Spanish daily ABC that in addition to Morón’s own strategic location, negotiations are underway to use the amphibious assault ship Juan Carlos I, the pride of the Spanish navy, as support when deploying U.S. Marines in harm’s way. Initial tests have shown the ship can handle MV-22 Osprey aircraft, six of which will be based at Morón.

The official text of the agreement between Madrid and Washington centers on operational questions and the amount of money to be expended (about $29 million in new infrastructure), but the Spanish government is not hiding its desire to build what amounts to a strategic defense able to slow Islamism where it is building momentum in northern and western Africa. Most especially, they are worried about the expansion of the Islamic State in Libya, and the relative ease with which it has carried out attacks on important tourist centers, like the recent beach massacre in Tunisia.

The AICS consultancy reports it has discovered jihadist training camps only eight kilometers from the Spanish enclave of Ceuta, in the area around the Moroccan town of Fnideq, a place through which many Moroccan Islamists have passed on their way to the Syrian war zone.

Once again, all signs point to this being a long struggle against ISIS and its ilk, which is why Morón will be home to thousands of U.S. Marines, most likely, for many years to come.