Any deal that emerges from the EU-Turkey summit in Brussels is likely to be deeply flawed and open to doubts, practical and moral. Some sort of deal is vital but there are limits beyond which – however desperate the migrant crisis – the EU should not go.

In the past week both sides have hardened their positions. There was no certainty that agreement would be reached last night. In the way of these things, any failure was not likely to be final but presented as “progress” towards a third attempt at accommodating the divergent interests and views of 29 nations.

The framework of the deal under discussion is distasteful but preferable to the existing inhumane chaos of people-smuggling gangs, child drownings and swelling refugee “jungles” in Greece. Migrants reaching the Greek islands would be sent back to Turkey. In return, the EU would take – one for one – an initial 72,000 genuine war refugees from the vast holding camps in Turkey.

The intention is to wreck the business plan of the people smugglers and to persuade Iraqi and Syrian refugees not to risk their lives by besieging Europe in their hundreds of thousands this summer. So far, so depressing – but necessary. However, European governments, under pressure from their own public, are right to insist on guarantees about the treatment of returned migrants by the Turks. The government of President Recep Tayyip Erdogan is refusing to apply the “relevant international standards” that the EU is demanding. For an Ankara government that seems hellbent on dismantling press and personal freedoms, that is not very reassuring.

There are other problems. Turkey is demanding fast-track talks on EU membership. Cyprus declines to consider this until Turkey recognises the country. Ankara refuses. Several EU countries, led by France, are, in any case, unwilling to give guarantees on early Turkish membership. Forms of words will be found to resolve these problems. The EU is good at forms of words.

It must, however, not enter a deal with Ankara which fails to guarantee minimum humanitarian treatment for the migrants pushed back across the Aegean. Such a commitment is the least we owe to the refugees. It would also force the Erdogan government to confront a simple truth. Turkey cannot expect to be treated as a European and democratic country while it tramples European and democratic values.

Ankara has a case for generous treatment by the EU. As the Prime Minister, Ahmet Davutoglu, pointed out yesterday, Turkey has received 2,700,000 refugees since the Syrian crisis began. Compare that with the few thousands grudgingly accepted by Britain. As part of the proposed deal, the EU would give Turkey up to €8bn (£6.2bn) in the next three years to help pay part of the cost of the migrant camps on the Syrian border. That is justified and long overdue. But the core of the deal – the migrant swap – must be seen to meet minimum international standards, even if some EU countries are reluctant to recognise those standards themselves. The 28 EU members have no choice but to deal with the Erdogan government, undemocratic though its behaviour sometimes is. Despite the press crackdown, there are signs that Ankara knows that it has overplayed its hand in recent years as it sought to become both a regional power broker and a beacon of “soft Islamism”, presuming such a thing exists.