It may once, but oh so briefly, have seemed like a good idea to invite Donald Trump to Britain. But for Theresa May it all turned into a wrecking visit by the ally from hell. To make things worse, it was entirely her own fault. And yet, strange though it is to relate, some good may unexpectedly have come from the Trump visit.

The British government did its absolute best – given that the streets of the cities were full of protesters – to lay on a glittering welcome for Mr Trump this week. Blenheim, Sandhurst, Chequers, Windsor – you don’t get much more in the way of British establishment red carpet than that. But this reckoned without the Trump character and, more sinisterly, the Trump political project. The president undermined Mrs May before he even left America. He bullied and lied at the Nato summit in Brussels. He then gave an explosive and deliberately destabilising interview to Rupert Murdoch’s Sun on the very day of his arrival in Britain.

This guaranteed that Friday’s press conference at Chequers would be purgatorial for Mrs May and maybe even a little chastening for the president and his team. And so it proved, in spite of what had clearly been the private reading of the diplomatic equivalent of the Riot Act to Mr Trump. But it was not just the rudeness that mattered – though rudeness does matter, a lot, both in personal and in public things. It was the political impact and consequence. That unmistakable consequence is that Mr Trump’s America can no longer be regarded with certainty as a reliable ally for European nations committed to the defence of liberal democracy. That is an epochal change for Britain and for Europe.

Everything about this disastrous and embarrassing presidential visit could have been avoided with more thought and more political sense. But Mrs May and her advisers rushed to Washington in January 2017 to offer a state visit to a president who had barely entered the White House, whose measure as an ally they had not yet properly taken, but who already had it in his character and his power to transform the event from a relatively harmless occasion into a deeply wounding one. It was a shameful and stupid misjudgment. The hostile public reaction was immediate and without precedent. Everything that has happened this week confirms that the Trump visit should not have taken place.

Mrs May should have grasped from the very start that Mr Trump was not an ally when it came to her Brexit strategy. Mr Trump wants to break up international organisations like Nato and the EU. He embraced Brexit on that basis. He saw it as the start of a swing back towards nativist, illiberal, often racist nationalist politics, of which his own election was a further example. He made no secret of his wish to promote other nativist movements on the right. Other European leaders understood this danger, notably Angela Merkel. Mrs May failed to do so. Mrs May rightly wanted a close post-Brexit relationship with the EU, a stance that led in time to the Chequers showdown with her Brexiteer ministers a week ago. But she failed to see that Mr Trump’s US has a stronger commitment to the weakening of the EU than it does to a Britain that wants the EU to prosper.

Out of that failure came the Sun interview. In the interview, Mr Trump expressed hatred for the EU, support for hard Brexit, unwillingness to strike a trade deal with the UK, contempt for Mrs May, support for Boris Johnson, hostility to immigration, and offered his barely coded belief that the UK – and Europe – is “losing your culture”. The interview, its content, its timing, and the fact that it was given to Mr Murdoch’s flagship anti-EU tabloid, was a deliberate hostile act. For Mrs May, fighting to control her party on the dominant issue facing Britain, it was simply a stab in the back. But it wasn’t fundamentally personal. It was a declaration of hostility to Britain and Europe and the values they stand for.

A president who supported the Atlantic alliance, the stability of Europe and liberal democratic values – in short, every other US president of the postwar era – would never have done such a thing. Such a president would have tried to help, would have seen the EU-UK problem as one that needed solving, and would have used his influence to get America’s European allies to find a shared way forward after Brexit. Such a president would have been doing the right thing.

But Mr Trump is not such a president. He is not our ally. He is hostile to our interests and values. He may even, if this goes on, become a material threat. This week he deliberately inflamed the politics of Europe and of Britain. Yes, Mrs May brought it on herself, but it was hard not to feel for her as a person over the last day and half. She now needs to learn the lesson, and to lead Britain, Brexit or no Brexit, into a constructive and effective relationship with our more dependable allies, who share our values, in Europe.