ANXIETIES about Donald Trump’s commitment to NATO and Russia’s military assertiveness remain at the top of the alliance’s agenda. But close behind looms the problem of semi-detached Turkey, a country that not only possesses NATO’s second-biggest armed force, but also straddles a critical geopolitical fault-line between west and east.

Turkey is not only unpredictable. It also pursues a nationalist agenda that can put it at odds with its obligations to allies. The most recent source of tension is the simmering row between Turkey and America over Turkey’s incursion into Afrin, a Kurdish enclave in north-west Syria. This is not, strictly speaking, a matter for NATO. However, American troops could soon find themselves under direct attack from their NATO ally if Turkey’s president, Recep Tayyip Erdogan, carries out a promise to “strangle…before it is born” a 30,000-strong American-backed “border security force”, composed largely of YPG Kurdish fighters whom Turkey regards as terrorists.

Mr Erdogan probably calculates that he can face down America, which is less interested in the region than he is. He may be right, but clashing interests in Syria are only one element in Turkey’s troubled relationship with NATO members. Well before an attempted coup in the summer of 2016, there were growing concerns within NATO about Turkey’s drift towards authoritarianism. In the aftermath of the botched coup, those fears have intensified. Mr Erdogan, resentful of what he took to be insincere expressions of support from the West (in contrast with Vladimir Putin’s full-throated congratulations), has embarked on a brutal purge of anyone suspected of disloyalty. Among the 50,000 arrested and 110,000 dismissed from their jobs for supposed links with the exiled cleric, Fethullah Gulen (regarded as the plotter-in-chief), are about 11,000 military officers and pilots.

According to one Turkish military analyst, 38% of Turkey’s generals were sacked. Many were singled out for being pro-Western secularists. Some 400 Turkish military envoys to NATO were fired and ordered home—many fled abroad rather than face jail—to be replaced by less qualified Erdogan loyalists, some of whom are actively hostile to NATO and sympathetic to its adversaries. General Curtis Scaparrotti, the alliance’s supreme commander, has complained of “degradation” in staff quality.

In another episode, German MPs were last year (not for the first time) refused permission to visit German air crews flying support missions into Iraq from two bases in Turkey, Incirlik and Konya. It looked like punishment after Germany had banned Mr Erdogan’s supporters from holding rallies on its soil in support of his campaign to extend the powers of the presidency. (He called the ban a return to “Nazi practices”.) After an intervention by NATO’s civilian chief, Jens Stoltenberg, the Turks eventually allowed the lawmakers access to the AWACS crews at Konya. But the Germans still moved their Tornados from Incirlik to Muwaffaq Salti, an air base in Jordan which America is expanding, at a cost of $143m, as an insurance policy in case they need to leave Incirlik.

The warmth of Turkey’s relations with Russia, particularly since the coup, is another worry. Mr Erdogan looks to his opposite number in the Kremlin as the man to do business with in Syria. He sees in him a strong and purposeful leader like himself. By cosying up to Mr Putin, he sends a message to NATO that he has other options. From Mr Putin’s point of view, Mr Erdogan gives him a means of dividing and weakening NATO and the West, which is his overriding strategic objective.

Red on blue

The most flagrant demonstration of Mr Erdogan’s Janus-faced foreign policy was the announcement in December that Turkey has signed an agreement to purchase two batteries of advanced S-400 surface-to-air missiles from Russia. The S-400 system cannot be integrated with NATO air-defence systems and, at least at first, will be set up and operated by Russians. Unless Turkey is frozen out of NATO information-sharing on countermeasures aimed at defeating the S-400, Russia can expect a windfall of intelligence.

Most worrying, Turkey is a partner in the F-35 programme and is due to take delivery of 116 of the stealthy fighter jets that will be the mainstay of NATO’s combat air capability for the next 30 years. Turkey will be in a unique position to hone the S-400 against the F-35, knowledge that Russia may well take advantage of. Some national-security commentators in America argue that Turkey should either cancel the S-400 or be told it cannot buy the F-35. The resulting confrontation could lead to Turkey marching out of NATO.

NATO officials are doing their best to put on a brave face. They point out that Turkey has also signed a deal with Eurosam, a European consortium building air-defence missiles, and that the S-400 may be just a stopgap. They also say that, in other ways, it is business as usual. Turkey is fulfilling its commitments to the alliance, for example by guarding Kabul airport and doing nothing to hinder a NATO-EU security agreement, which it could have blocked. There is sympathy, too, for Turkey’s vulnerability to terrorism and praise for the refugee burden it has borne. And even if there were a mechanism for suspending or expelling Turkey from NATO, which there is not (although its tarnished democratic credentials would prevent it joining the alliance as a new member), its geopolitical importance is as great as ever.

The hope is that Mr Erdogan knows that Russia is using Turkey for its own purposes, and that it is no substitute for NATO as a long-term security partner. It is possible, too, that his post-coup paranoia will abate, although there is little sign of it. But as with many unhappy marriages, the reality is that—however fraught their relationship—Turkey and NATO have little choice but to try to make it work.