IN THE glory years of the Ottoman empire, foreign dignitaries seeking favours would flock to the court of the sultan bearing lavish gifts and singing hymns of praise. Europe’s leaders now find themselves in a similar position, driven to desperation by the mass of refugees streaming into the European Union from Turkey this summer.The offers they made this week to Recep Tayyip Erdogan, Turkey’s increasingly autocratic president, may not have the lustre of precious gems or embroidered textiles. But they are no less valuable.

On October 15th Europe’s heads of government, meeting in Brussels, endorsed a “joint action plan” agreed with Turkey by the European Commission a few days earlier. The EU wants Mr Erdogan to do two things. First, improve the lot of the 1.7m Syrians living in Turkey who are not in refugee camps, in particular by increasing their access to the labour market (right-to-work legislation is currently languishing in the Turkish parliament), and by providing more places in schools. By making life more bearable for Syrians in Turkey, the EU hopes fewer will wish to leave for Europe.

Second, the Europeans want Mr Erdogan to stem the disorderly flow of migrants leaving the Turkish coast for Greek islands. Under the plan Turkey will boost border patrols, increase co-operation with Greek and Bulgarian authorities and tighten its own visa restrictions for the likes of Pakistanis and Bangladeshis, many of whom traverse Turkey to reach the EU.

In exchange, Mr Erdogan is seeking around €3 billion ($3.4 billion) in aid, via an EU trust fund. Visa-free travel for Turks inside the EU’s Schengen zone, another big prize, may be granted next year, if Turkey agrees to readmit illegal third-country migrants who reach Europe via its territory. Perhaps most strikingly, the leaders agreed last night to “re-energise” Turkey’s long-stalled bid to join the EU. This would come via the opening of fresh “chapters” (negotiations in specific policy fields).

It all amounts to a striking change in European attitudes to Turkey: the EU had contemptuously stalled Turkey’s EU accession process even before Mr Erdogan lurched towards authoritarianism, mostly because of resistance from the likes of France and Cyprus.

Many details remain to be filled in, and some governments are hostile. Austria and Cyprus remain sceptical about accelerating Turkey’s membership bid, for example. A further Turkish demand—to be placed on a list of “safe countries of origin”, meaning that the small number of Turkish nationals seeking asylum in the EU would struggle to obtain it—also faces opposition from some European governments. Not even the money is guaranteed: bar the €500m or so that can come from the EU budget, governments will have to scrape together the cash themselves, and there are no pledges yet. Mr Erdogan wasted no time jabbing at the Europeans today, accusing them of “insincerity”. On the Turkish side, it is not clear how some of the government’s assurances can be verified. The migrant flows will soon slow thanks to cooler weather, for example; how will that effect be disentangled from Turkish efforts at the border?

Yet what was most important to the Turks, say European officials, was not this or that offer but a sense that their relations with Europe have been restored to a proper political footing, rather than being reduced to legalistic exchanges between technocrats or one-sided hectoring on human rights. Mr Erdogan, for example, wants to be invited to hob-nob at some European summits, and will probably be granted his wish. On October 18th he will receive the most powerful European of all, when Angela Merkel, the German chancellor, makes a hastily arranged visit to Ankara to pay tribute. (Mrs Merkel’s government, facing the brunt of Europe’s refugee challenge, has been the loudest voice urging a deal with the Turks.)

For Mr Erdogan, the timing is delicious. On November 1st Turkey holds a general election, after a previous vote in June proved indecisive. The president is not on the ballot but his Justice and Development (AK) party, which has been in office since 2002, is struggling to win the majority it would like to change the constitution (to grant, among other things, sweeping executive powers to the presidential office). Most observers expect another inconclusive result, but the sign of mighty Europeans showering the president with presents will not harm AK’s prospects.

This, of course, makes matters awkward for the Europeans. Publication of the commission’s annual progress report on Turkey’s accession bid, originally scheduled for this week and rumoured to contain tough language on media freedom and corruption, has been shelved, with no fresh date announced. Members of the European Parliament and others who fret about the deterioration of human rights under Mr Erdogan are already crying foul.

These are critical times for Turkey. The political stability and economic success that were the hallmarks of AK rule are disappearing. Turkey’s conflict with the Kurds has flared up again. On September 10th, in Turkey’s worst-ever terrorist incident, at least 99 people were killed by twin bombs at a peace rally in Ankara. A surge of fighting in the Syrian city of Aleppo could send fresh waves of refugees into Turkey, and perhaps thence to Europe. Mr Erdogan therefore has rather different priorities from his European partners, and it remains to be seen how much of the action plan will translate from deal to deed. But for now, the sultan will be satisfied with the homage.