The aggressiveness of Turkish foreign policy is something new. It goes back to 2009 when, at Davos, President Erdoğan insulted Shimon Peres, then Israel’s president, using the Turkish form of “you” that is normally used for dogs, and accusing him of atrocities in Gaza. That went down very well with his home constituency, less well with Turks who think about things, and it also went down well in the Arab world.

Erdoğan was lionised, and cut a big figure in the Arab spring that followed. In particular he tried to bring about change in Syria, and was much put out when President Assad did not respond to his urgings for reform, a reform that would have applied some version of Erdoğan’s own “Muslim democracy”. Expecting Assad to fall, he did nothing to stop the civil war that then erupted, and gave a hospitable welcome to more than 2 million refugees who flooded over the border.

He no doubt expected them to go back within weeks. They did not, and the Syrian mess has become more and more complicated, particularly by the emergence of a Kurdish entity on Turkey’s border. That entity could be a threat to Turkey’s own territorial integrity, given that south-eastern Turkey is largely Kurdish. The Russians then took a hand, directly supporting Assad, their man in the Levant, and driving his opponents back. And Turkey shot down a Russian bomber, an episode that from a Turkish perspective was utterly without precedent, even during the cold war. Where this will lead is anybody’s guess, but the consequences may be such that the framers of Turkish foreign policy will look back on the old days with nostalgia.

When the country finally got its present shape, in 1923, there were all sorts of loose ends – the longest, and the one with a fuse attached, the eastern border with northern Iraq, ie Kurdistan. The British fixed that border in 1926 with their own oil interests in mind, whereas the Turks regarded that part of the world as naturally belonging to them. However, they accepted the arrangement, and until recently pursued a prudent foreign policy, on the lines of their founder Kemal Atatürk’s words: peace at home, peace abroad. No adventures.

When Turkey did move forward, in 1938 over the Antioch area or in 1974 over Cyprus, it did so by invitation and with solid treaty-backing. Otherwise it was extra careful, especially where Russia was concerned. Although there were embittered Caucasian exiles all around – half of the urban population in the 1930s had been born abroad – Caucasus exile literature was forbidden, and a prominent central Asian scholar was imprisoned in 1945 for provoking trouble with Russia.

The reasoning behind all of this was simple enough. Russia was hugely powerful, had defeated the Ottoman empire in a dozen wars, but had also played a decisive part in protecting the new Turkish republic. The Russians sent gold and weaponry to the Turkish nationalists, and did a deal over borders, in effect swapping Armenia for Azerbaijan. Later on, they swapped Trotsky for a shirt factory, and a Russian took charge of energy planning. In return the Turks sacked pan-Turkists from Istanbul University and imprisoned a prominent scholar, ZV Togan.

That all came to an end after the second world war, when Stalin showed his teeth. He demanded a base in the Dardanelles and territories in eastern Turkey. The Americans and British supported the Turks, who abandoned their neutrality and joined Nato, having fought in the Korean war. They got Marshall aid and, given the enormous importance of their location, had a privileged position: thousands of students abroad, much help from the IMF, access to European markets and especially the German labour market.

The Anglo-American connection has been very important in lifting Turkey out of the Middle East – it now has an economy worth more than any of its local rivals, and then some. Since the American alliance at least implied democracy, the Turks had a free election in 1950. And the government that resulted was the grandfather of the present one. It made whoopee with state firms, and ensured popularity by giving Islam positions that the earlier republicans had denied it.

They had not actually persecuted Islam except in the sense that they stopped it from persecuting. “Houses of the people”, on a Soviet model, had gone up in the villages to teach literacy and healthy ways to poverty-stricken peasants for whom the imam was the natural guide, as was the priest for poverty-stricken peasants in rural Ireland or Italy. The 1950s government closed down the “houses of the people”, and mosques went up instead. There are now more than 80,000.

A mania, yes, but at bottom not so very different from the Victorian church-building that affected every street corner in England. Rural migrants need a centre, and that centre can mobilise their votes. The interesting question in Turkish politics is the failure of the left to divert them from the mosque. In effect the army had to take the role of the left, with coups from time to time, ensuring women their rights, and making sure that education was not entirely dominated by Qur’anic recitation.

There were (and, God knows, are) intelligent and sensible people on the religious side, and they know that religion should not be rammed down people’s throats. The real great man of modern Turkey is Turgut Özal, who outwitted the military in the 1980s, opened Turkey up to the exporting world, and created the (mostly) successful country of today. He had a strict religious background, but knew abroad (he had worked in the World Bank) and also understood that there would be real trouble if he pushed religion too far. He was part-Kurdish and knew that the problem there was that Turkey had allowed the Kurds to feel like second-class citizens. Above all, he understood the importance of keeping to the prudent tradition of Turkish foreign policy. He died in 1993, and no one has taken his place.

Özal was Turkey’s Thatcher (they got on very well) and the 1980s release of energy has carried Turkey to its present prosperity – its businessmen all over the world, its airline maybe the best, its writers read, its government everywhere consulted. But politics being complicated, he did not leave a conservative block that would perpetuate his legacy. Instead, we have the religious AKP, with an all-powerful leader, Recep Tayyip Erdoğan, who has made it his duty to raise “pious generations” and who is helping his Muslim Brotherhood allies in the Syrian civil war.

It is also obvious that Islamic State has had help from Turkey, since the overthrow of the defiant Assad is Erdoğan’s priority, although the vastly respected editor of the country’s most venerable newspaper has been detained pending trial for publishing the evidence. And then there are the Kurds, clearly getting their act together. They are, as their greatest figure in Turkey, Kamran Inan (an Özal associate who has just died), said, “a wounded people”, partly alienated from Turkey, and the rest of the world now sees in Kurdistan a possible solution. Erdoğan’s adventurism has been quite successful so far, but it amounts to an extraordinary departure for Turkish foreign policy, and maybe even risks the destruction of the country. How on earth could this happen?

The background is an inferiority complex, and megalomania. For centuries, and even since the Mongols, sensible Islam has asked: “What went wrong? Why has God forsaken us, and allowed others to reach the moon?” And now Turkey stands tall, a voice unto the nations (and Tayyip Erdoğan, from his training on the soccer pitch and a religious school, indeed has a voice, part uplift-sermon, part referee-harangue, though its rhetorical effect does not translate).

Chancellor Merkel comes begging for help in the refugee crisis, and the Europeans shut up about editor-imprisoning. All of a sudden, they agree to change the visa system that humiliated Turkish businessmen and academics. The Americans can be managed. In the old days, Turkey had two foreign policies towards Washington, which controlled the IMF purse strings – “me, too” and “oh dear”. Now it is more likely to be the US adopting those positions.

President Erdoğan sits in his Chinese-airport palace and sees himself as restorer of the Ottoman empire. In the Ottomans’ great period, the 16th century, Russia was just a sort of noise off to the north. But in challenging it, the good President Erdoğan will find something a great deal more formidable. In breaking with the traditions of Turkish foreign policy, he has forgotten that the death blows come not from the west, but from the east – Iran and Syria, the army of which twice reached Istanbul in the 19th century.

Now it seems that the western powers will cooperate with Russia in tacit upholding of Assad, in pursuit of the greater enemy, Isis. In other words, Turkey might just be isolated. In this latest affair, is there an element of provocation – that if Putin responds harshly to the downing of his aircraft, the Americans will be pushed into proclaiming a no-fly zone behind which Erdoğan can quietly deal with the enemies whom he wants to deal with, the Kurds, who now amount to the main challenge to his regime? He has been immensely successful so far, but is this the step that will bring him down, as his tame central Anatolian constituency begins to feel the winter cold? If there is one lesson for a ruler of Turkey it is this: do not provoke Russia.