Air Force One landed in France on Friday bearing a wounded president. Donald Trump has reacted to the loss of the House of Representatives to the Democrats with characteristic petulance, lashing out at journalists, especially African American female reporters. The gloves are off – they were only half-on anyway – and what lies beneath is as ugly as anything we could have imagined.

The insults and irritation belie his show of nonchalance after Tuesday’s midterm elections. Trump has been knocked back. Republicans no longer control all branches of government and the Democrats have established a bridgehead from which to harry him, demanding his mysterious tax returns and preventing him from burying the investigation into his campaign’s ties to the Kremlin. For a president who was never comfortable with the separation of powers, Tuesday was a nightmare. Trump’s reflexive response was to claim the defeated Republicans had made the mistake of being disloyal to him. It was a typically Trumpian reaction, self-absorbed and false. Out of the 75 Republicans he endorsed in congressional contests, only 21 won their races. In contrast, Barack Obama endorsed 74 Democrats, of whom 39 emerged as winners. On the whole, siding with the president was not a winning ticket.

The suburbs, home to the educated middle class, largely deserted Trump. In the 2016 presidential election, he lost the popular vote by nearly 3m. In House races last week, Democrats won almost 5m more votes than Republicans, with notable gains in Wisconsin, Michigan and Pennsylvania, three states that were key to Trump’s victory two years ago. And in the perpetual nailbiter state Florida, where votes are still being counted after Tuesday’s race, an amendment was passed that gave the vote to people with felony convictions. Black Floridians are disproportionately likely to be arrested and convicted and disproportionately likely to vote Democrat. The amendment could help the blue side to victory in 2020 when Trump stands for re-election.

The other half of the story is more nuanced. Trump has been rebuked, but not necessarily contained. While he lost the suburbs, his rural supporters dug in. Wyoming, with its 600,000 residents, sends the same number of senators (two) to Congress as California, population 40m. Thirteen million more Americans voted for Democratic candidates than for Republicans in Senate races, but it does not matter. Trump has consolidated his hold on the chamber, where the incoming Republican majority will arguably be even more loyal. That makes it easier for Trump to confirm even highly dubious nominees for high office and therefore easier to fire incumbents who resist him. His first act after the midterms was to fire his inconvenient attorney general, Jeff Sessions, and more house cleaning is expected.

Trump has brandished his Senate majority at the House Democrats, warning that if they investigate him for links to the Kremlin and financial improprieties, the Senate will investigate his enemies, with due cause or without. “Two can play that game,” he tweeted, making clear he was ready to lock down government in duelling inquiries and allow Democrats to take the blame. Keeping hold of the senior chamber seems to have emboldened him into throwing more political and constitutional norms on to a raging bonfire. The appointment of rightwing activist Matthew Whitaker as acting attorney general is constitutionally questionable and politically transparent. Whitaker has been a relentless critic of the Russia investigation, run by ex-FBI director, Robert Mueller, deriding it as a “political fishing expedition”.

The greatest danger is that Trump finds his agenda stymied by the Democratic-run House, under threat from congressional committees armed with power of subpoena, and goes looking for spectacular distractions abroad. There is nothing like a foreign crisis to help portray investigations of the commander-in-chief as unpatriotic. A Democratic House might shackle his domestic agenda, but he will still have a free hand in foreign policy. The War Powers Resolution, intended to curb the president’s ability to take the US into conflict, is no longer much of a constraint, thanks in large part to Trump’s predecessors chipping away at it.

In the first two years of his presidency, Trump swung from threats to obliterate North Korea to declarations of love for Kim Jong-un. As it becomes increasingly clear that the young dictator has no intention of disarming, it is quite possible that Trump will choose to swing back to the brink of war. An escalation of the brewing trade war with China, along with a continuing military stand-off in the South China Sea, is also a reasonable bet. It is a policy that draws support from both sides of the aisle.

And the Trump administration seems bent on bringing Iran to its knees with an oil embargo, demanding Tehran submit to a dozen maximalist demands, all but goading Iranian hardliners to lash out.

The Democratic recapture of the House may have given some satisfaction to Trump’s critics, but for the next two years it could make the world a more dangerous place.

America’s friends and enemies will be watching closely what happens to the defence secretary, James Mattis, who has acted as a check on some of the president’s wilder impulses, much to Trump’s frustration. If he feels strong enough to replace Mattis, a big if, as the stern marine veteran is popular with congressional Republicans and the military, we will know we are really in trouble.