Whenever Madrid and Jerusalem quarrel — which under Pedro Sánchez is most weeks — a familiar chorus starts up. Spain, it explains, has been the enemy of the Jews since the Inquisition, and whatever its current government does is simply the old poison decanted into new bottles. The theory has the advantage of requiring no knowledge of Spanish history, which explains its popularity.

The record is worth consulting, if only because it keeps refusing to cooperate. Jews have lived in Iberia longer than almost anywhere else in Europe. Obadiah 1:20 speaks of exiles from Jerusalem dwelling in Sepharad, a place the classical commentators identified with Spain; modern scholars doubt the identification, and the first unambiguous traces of Jewish life in the peninsula date to the Roman period.

In the thirteenth century, Alfonso X of Castile — el Sabio, the Wise — compiled the Siete Partidas, the seven-part legal code that shaped Spanish and Latin American jurisprudence for centuries and whose traces can still be found in Louisiana law. An entire title within it is devoted to Jews. It affirmed their subordination and fenced their lives with restrictions. Yet the same title placed synagogues under royal protection — Christians were forbidden to destroy or deface them — and banned forced baptism in categorical terms. It even provided that a Jew could not ordinarily be summoned to court on his Sabbath.

This was the same king who kept Jewish astronomers on his payroll; the Alfonsine Tables they produced for him steered European astronomy for the next three hundred years, all the way to Copernicus. Set the legislation against its own time — kings elsewhere were squeezing their Jews for revenue before showing them the door — and the Partidas stand as one of medieval Christendom’s rare experiments in legislated coexistence: unequal by design, and still more than nearly anyone else attempted. When Alfonso buried his father, Fernando III, in Seville, he had the epitaph carved four times over: in Castilian, Latin, Arabic — and Hebrew.

Persecution deepened over the following two centuries, and in 1492 came the Alhambra Decree and the expulsion. Spain arrived late to the practice: England had thrown out its Jews in 1290; France did the same in 1306 and, for good measure, again in 1394. Among the major kingdoms of Western Europe, the Spanish were nearly the last. Yet somehow only they are still made to answer for it five centuries on — the Black Legend has a long half-life — while nobody thinks to invoice a modern Englishman for the deeds of Edward I.

The twentieth century produced a stranger chapter, and it opened with a gesture no caricature of Spain can digest: in 1924 the dictator Miguel Primo de Rivera issued a decree inviting the Sephardim — whom Senator Ángel Pulido’s long campaign had dubbed “Spaniards without a homeland” — to reclaim Spanish nationality. The window closed in 1930 with few takers. Twenty years on, that piece of paper would save more lives than its author ever imagined.

Franco’s Nationalists won the Civil War with German and Italian help, and the state they built never concealed where its sympathies lay. The Caudillo’s own view of Jews, as recorded in his speeches, articles and policies, mixed the Catholic anti-Judaism of his formation with the Judeo-Masonic-Bolshevik conspiracy talk of interwar Europe — and, sitting oddly beside both, a genuine philosephardism, an admiration for the Sephardim and their weight in Spanish history.

During the world war, Madrid slid from neutrality into “non-belligerence” and supplied the German war economy; the Blue Division went off to fight the Soviets, though formal entry into the Axis never came. In 1941 the regime compiled a detailed register of roughly 6,000 Jews living in the country, a document reportedly passed on to Himmler’s SS. Yet no program of deportation or extermination ever operated on its soil. Tens of thousands of Jewish refugees crossed the peninsula on their way out of Hitler’s Europe, most of them funneling toward the rail crossing at Vilar Formoso on the Portuguese frontier and the ships at Lisbon. Spanish diplomats shielded thousands more abroad.

One of those diplomats deserves his own paragraph. Ángel Sanz Briz, chargé d’affaires in Budapest in 1944, took Primo de Rivera’s dormant decree and stretched it until it covered thousands of Hungarians who had never seen Spain. He handed out protection papers, rented apartment blocks and placed them under the Spanish flag; more than 5,200 people were ultimately saved from deportation. Yad Vashem recognized him as Righteous Among the Nations in 1966. Spaniards remember him as the Angel of Budapest.

Historians still argue over how much of this reflected official policy and how much the initiative of individual envoys. Enrique Moradiellos, among the leading scholars of twentieth-century Spain, concludes that none of it could have gone on against the dictator’s orders: Franco kept the last word on foreign affairs and permitted his diplomats their margin. A verdict has to hold all of it at once: for all his philosephardism, the man was no friend of the Jews, and his state no annex of the Third Reich. The file contains antisemitism, opportunism, obstruction and genuine rescue — sometimes in the same year.

What followed the war is the part almost everyone gets backwards. Franco sought relations with the new State of Israel, calculating that recognition from Jerusalem might ease Madrid out of its diplomatic quarantine. He was rebuffed. Ben-Gurion’s socialist government wanted no part in rehabilitating the dictatorship, and at the United Nations Abba Eban delivered a scathing indictment of Francoist Spain — though even Eban conceded that the Spanish had taken no part in the extermination of European Jewry. In 1949 Israel voted against letting UN members return their ambassadors to Madrid, and the following year against revoking the boycott altogether — the whole episode is reconstructed in the historian Raanan Rein’s In the Shadow of the Holocaust and the Inquisition, the standard account of the relationship. The rejection pushed Franco deeper into the Arab embrace, and the embrace paid. By the mid-1950s the roles had swapped: now Israel came asking, and Madrid declined, unwilling to trade the Arab world for a state that had spurned it. Quiet contacts continued all the same.

Then comes an episode that has been largely forgotten outside the academic literature. When newly independent Morocco barred its Jews from leaving for Israel, Francoist Spain knowingly allowed the Mossad to run an escape corridor across its territory. Between 1957 and 1961, consuls issued entry permits behind Rabat’s back, and officials in Ceuta, Melilla, Algeciras and Málaga waved through emigrants traveling without the usual documents. Some of Mossad’s agents were issued Spanish passports that allowed them to enter Morocco without a visa. Isser Harel, who ran the agency in those years, wrote in his memoirs that the cooperation was “above and beyond every expectation.” In a dictatorship as centralized as Franco’s, nothing on that scale runs for four years without a nod from the very top.

As many as 25,000 Moroccan Jews reached Israel along this route, a great many of them through Ceuta and Melilla — the two Spanish cities that made news last week, and whose Spanishness can be doubted only by the historically illiterate. Franco’s motives were not entirely humanitarian: hostility toward Rabat played its part, as did the appetite for intelligence ties with Jerusalem. But motives do not erase deeds. Madrid earned gratitude for this from the very state that had voted to keep it in quarantine, and it has yet to collect so much as a plaque.

Democracy arrived, and with it, at last, normality. Diplomatic relations were established in 1986. In December 1991, weeks after hosting the Madrid Peace Conference, Felipe González became the first Spanish head of government to visit Israel, where he addressed the Knesset. The following spring, five hundred years to the day after the Alhambra Decree was signed, President Chaim Herzog stood beside King Juan Carlos in the Beth Yaacov synagogue, where the monarch, wearing a white kippah, honored the Jews his predecessors had driven out. In 1993 Juan Carlos followed with a state visit, the first by a reigning Spanish monarch to the Jewish state. In 2010 José María Aznar, prime minister for eight of the intervening years, founded the Friends of Israel Initiative — headquartered, of all places, in Madrid — to fight the campaign of delegitimization, warning that if Israel goes down, we all go down. And in January 2020, when dozens of world leaders gathered in Jerusalem to mark seventy-five years since the liberation of Auschwitz, the man chosen to speak on their behalf was Felipe VI of Spain.

None of this describes a nation congenitally hostile to Jews or to their state. Relations have often been strained, and just now they are dismal. But the animus runs along ideological lines, and it always has. Ben-Gurion’s socialist Israel shunned Franco’s Spain. Today the poles have reversed, and Sánchez’s socialists keep Netanyahu’s government at arm’s length. Ideologies pass. When the political weather clears — and sometimes, as the Moroccan corridor proves, even when it does not — the two countries cooperate without the slightest difficulty.

As for the deeper history: at its darkest, the country’s treatment of its Jews was no crueler than what the rest of Western Europe managed, and at certain moments it was considerably better. Those who prefer the theory of the eternal enemy are welcome to it. They will simply have to explain the flag that flew over the safe houses of Budapest — and the two Spanish cities through which thousands of Moroccan Jews once passed on their way home.