The best account so far of the extraordinary events that unfolded on the floor of the US Senate on Thursday night seems to be that published by Ed O’Keefe of the Washington Post at quarter to six in the morning. He crisply describes the drama and the way in which the Republican leadership’s attempts to dismantle Obamacare were torpedoed by Senator John McCain, the former Republican candidate for the presidency and war hero.

The vote was going to be tight, so Vice President Pence was on hand to cast the deciding vote in the event of a tie. Pence tried to plead with McCain (recently diagnosed with brain cancer) not to vote against the scrapping of Obamacare. At the appointed moment, McCain stepped forward during the roll call and uttered a quiet “No” that reverberated. The Trump-backed effort was scuppered.

It was mesmerising stuff, and the biggest, but most dignified, rebuff to Donald Trump since he won power.

Trump in winning the 2016 election turned politics upside down. Yet, as an egomaniac, who even managed to ruin what should have been a non-controversial speech to the Boy Scouts jamboree the other day, the thrill of getting away with everything, of subverting the system, has clearly gone to his already swelled head. During his populist, insurgent run last year he broke all the conventional rules and in this strange climate found himself rewarded for it. So he keeps on doing it.

There are limits though, and how delicious it is (regardless of your views on US healthcare) to see McCain teach Trump a lesson about how politics works.

Trump is utterly fixated on himself. That is why that speech to the Scouts featured weird rambling nonsense about Manhattan cocktail parties. It was stylistically straight out of Goodfellas, in tone if not content. Why would young Scouts be interested in that or in a lecture on Trump’s magnificence in the electoral college?

That self-obsession means he struggles to appreciate that other people have ambitions and feelings, and that they remember and sometimes bear grudges, taking revenge down the line. Understanding other people and their motivations is a key skill at the top of American politics, with its system of checks and balances and the need for persuasion to get anything done. Lyndon “Master of the Senate” Johnson was an expert practitioner, as was Harry Truman. Ronald Reagan at his best could persuade. Bill Clinton early in his presidency was good at it.

They were all inquisitive albeit ruthless people, who thought intelligently about how power works. Trump doesn’t listen. He thinks of power in terms of televised wrestling and stupid loyalty tests, or like Joe Pesci and the other hoods in Goodfellas. Trump’s the “made man,” the President, therefore the lesser man, McCain, owes him respect, surely?

Nope. Not when Trump defiles the office and behaves like a man-child, and has insulted McCain in such a memorable fashion.

And there’s the lesson. It was payback time. Remember, Trump – an avoider of the Vietnam draft – famously rubbished McCain’s war record. McCain was held in the Hanoi Hilton as a prisoner of war for more than five years and subjected to torture. He was released in 1973.

Trump said of this: “He’s not a war hero. He’s a war hero because he was captured. I like people who weren’t captured.”

McCain waited, popping up at various points to comment on Trump’s antics and to play a role in the Russian dossier business. That was only the warm-up. Last night he picked his moment for revenge with murderous precision and sunk Trump and the Republican leadership that has done his work. Pure politics. Awesome, as the Americans say.

What are the implications? There will now be attempts to patch together a compromise, but the supposed running order of the Trump agenda – healthcare victory, leading into tax reform, and then related infrastructure spending – is humiliatingly derailed. Less than a year in, and even before the mid-terms, there is a lame duck feel about it all. Meanwhile, the White House continues its meltdown with Mr Scaramucci, the new White House Communications director, demonstrating that he does not know the basic difference between on and off the record.

John McCain is hardly perfect. He was a very poor candidate for the presidency in 2008 against Barack Obama. American campaigns usually have a wonderful way of revealing character flaws under pressure. At the two crucial moments, when he picked Sarah Palin as his running mate, and then during the autumn financial crisis, when he halted his campaign and had no answers and Obama stayed cool, McCain blew it.

But he is a patriot, and a politician of considerable ability and skill. This week he taught the blowhard in the White House a lesson on how the world works.