Theresa May blew it. She had nine months to prepare a speech on Brexit - described by others as the most important any British prime minster has delivered in the past half a century. And she cocked it up.

The day the UK became the first country to formally initiate proceedings to leave the European Union, she got the tone all wrong. She threatened. If you don’t give us the trade deal we want, we will cut off police and security co-operation. Or more crudely, give us what we want, or we’ll let ISIS bomb your cities.

Needless to say it played very badly across Europe. Not only was it crude, unpleasant and unnecessary, it was self defeating. It hardened the mood, playing into the hands of those who would like to give the British a good slapping.

It was also utterly pointless, because the EU is ready and willing to do a deal on both free trade and security co-operation ("in particular the fight against terrorism and international crime, as well as security and defence", according to paragraph 19 of the EU negotiating guidelines published on Friday morning).

Judging by the amount of co-ordination between Mrs May's formal letter and the negotiating guidelines (and the hints and leaks that preceded both) the British knew full well security co-operation was going to form part of the final deal (they had been raising the issue for at least six months). But they just couldn’t help themselves - they had to be nasty about it.

The thuggery was unmistakable 'Nice European Union you got there - shame if something was to happen to it,' was the message, received loud and clear in the capitals of the 27.

The next day the Brexit minster David Davis was sent out to tell us that we had all got it completely wrong, that there was no threat at all, just a statement of fact. Unfortunately his colleague Amber Rudd, the Home Secretary (who is in charge of police and security) had already stated that the UK is the biggest contributor to Europol, and "If we left Europol (the EU’s law enforcement agency), then we would take our information ... with us".

But it was the Prime Minster of Malta who let us in on the real story - that the British government had to spend a good deal of time on Thursday phoning around other EU capitals to try and row back from the threat to link security co-operation to trade deals.

On Friday morning, European Council President Donald Tusk gave the British a lesson in the fine art of diplomacy, saying: "Especially after the terrorist attack in London, it must be clear that terrorism is our common problem. That is why I rule out this kind of interpretation and speculation that security co-operation is used as a bargaining chip. It must be a misunderstanding … I am absolutely sure no-one is interested in using security co-operation as a bargaining chip."

This isn’t the first time the British have used threats during the Brexit process. In her Lancaster House speech, the big set piece that outlined British policy, Mrs May threatened to turn Britain into a North Sea version of Singapore, slashing taxes and regulation to lure in Foreign Direct Investment, if the EU did not give it the kind of trade deal it wants. Such language was notably absent this week.

But it had provoked a response from the EU. Friday’s draft negotiating guidelines say any future free trade relationship with the UK "must ensure a level playing field in terms of competition and state aid, and must encompass safeguards against unfair competitive advantages through, inter alia, fiscal, social and environmental dumping".

Having backed off the Singapore threat, the security threat was all the more surprising, as the Lancaster House speech had attempted to reassure other states by suggesting security was not a bargaining chip.

Although the two issues were linked - in that she suggested that common interests in security co-operation were one of a number of reasons why she expected a free trade deal would be struck - she did not imply a quid pro quo. 

Indeed she said: "After Brexit, Britain wants to be a good friend and neighbour in every way, and that includes defending the safety and security of all our citizens." 

She also said: "A Global Britain will continue to co-operate with its European partners in important areas such as crime, terrorism and foreign affairs". No conditions attached. And a few lines later: "With threats to our common security becoming more serious, our response cannot be to co-operate less, but to work together more."

Hence the surprise at Wednesday’s volte face. Hence the panicked reaction from London, having to spend ministerial and senior official time explaining its position. And as the old American saying goes, when you are explaining, you are losing.

European People's Party leaders including Barnier, Tusk, the Taoiseach, Merkel and Juncker, received May's letter - and nasty speech - at their party congress meeting in Malta. 

Maybe that's what made me think of a line from Humphrey Bogart's Sam Spade character in the movie 'The Maltese Falcon' - "the cheaper the crook, the gaudier the patter". (You know the movie - it's about greedy people who turn nasty over recovering an ancient treasure, redolent of past glories, that turns out to be fake).

Which is unfortunate, because there is quite a lot of common ground between May's Article 50 letter and Tusk's negotiating guidelines. They both seek to land in broadly the same place - an orderly withdrawal by Britain from the EU, legal certainty for citizens, businesses and other countries, a comprehensive free trade agreement, and close co-operation in a range of policy areas, including security and defence (even though Britain has always insisted defence is a matter for NATO, and has been one of the biggest obstacles to increased defence co-operation in the EU).

Mr Tusk's negotiating guidelines spelled out a sequence of talks - first sort out the terms on which Britain will leave the EU, then move to discussions on the future relationship, including trade and security. But no deal can be done on the latter until after the UK leaves. 

This came as no surprise whatsoever to anyone who has ever read Article 50, as this is precisely the legal pathway it sets out. Talks on trade and other issues will start during the next two years, but they will not - legally cannot - be concluded within that period. The EU guidelines explicitly stated - and the British letter implicitly accepted - that there will have to be transitional arrangements to smooth out the transition from 28 to 27.

A deal is there to be done, but a big impediment to doing it is the inability of British leaders - starting with Theresa May - to control their urge to be nasty.