For most of Donald Trump’s brief political career, chaos has been his friend. He draws energy from an endless storm of difficulties and controversies that would send most presidents into the fetal position.

Critics and supporters alike compare his presidency to a reality television show, one that always ends with the leading man getting the last word. From Russia, Russia, Russia to Ukraine and impeachment, Trump’s time in the White House has been a continuing roller-coaster ride between danger on one side and disaster on the other.

A political Houdini, he has always escaped and emerged stronger in victory, but now comes the biggest test. He is in the middle of his reelection campaign just as public disorder is expanding and accelerating, leaving many Americans extremely unsettled and fearful about the future.

For the president, the outcome could turn on the question of how much chaos is too much chaos. And whether independent voters will abandon him because of Trump fatigue.

Elections, of course, are referendums on the incumbent and, pre-pandemic, the president was in the driver’s seat. The economy was roaring, unemployment was at record lows and he finally appeared to be comfortable with his White House team.

Democrats couldn’t find either an issue to run on or a strong nominee. Socialism was a loser and one shooting star after another flamed out — remember the glory days of Pete Buttigieg? — until only a confused Joe Biden was left standing. His infirmities are so obvious that Barack Obama didn’t endorse him until there were no other options.

Yet the nation’s mood has shifted sharply in the last three months, with the pandemic roiling the political and economic landscape and giving Biden a fresh chance at victory. Dems and their media handmaidens are determined to hang every one of the 100,000 deaths around Trump’s neck and use the enormous job losses as an indictment against the president’s ­tenure.

If that weren’t trouble enough for the incumbent, just as the pandemic begins to recede from the headlines, other disturbances already are beginning to eclipse it.

Start with the most sudden and sensational: the brutal death of a black man in Minneapolis at the hands of police officers, one of whom was charged with murder.

Protests quickly turned into ­riots, looting and arson, the National Guard is patrolling the streets and sporadic anti-police violence is spreading. The prospect looms of a long, hot summer of urban unrest.

Simultaneously, the president’s simmering feud with Big Tech also erupted. Twitter dropped its pretense of political neutrality to fact-check Trump tweets, effectively declaring that it has joined the resistance and has no intention of dropping its long-standing bias against the president and his supporters.

The double standards are glaring, but Big Tech is now too big to scare. Threats from Iranian mullahs and far-left nut jobs who talk of assassinating Trump are acceptable posts, but the president of the United States gets the bum’s rush.

Trump, naturally, hit back hard, drafting an executive order calling on the Federal Communications Commission to end the social media giants’ legal liability exemptions. The result could alter the handful of companies that dominate digital advertising and personal communications.

While many on the left have longed for tighter regulation of the tech firms, they also clamor for restricting Trump’s access. His embrace of regulation will probably turn them into ardent defenders of the legal exemptions and give them an opportunity to claim, falsely, that he wants to abolish the First Amendment.

The final bombshell of last week may turn out to be the most consequential. Clearly exasperated by China and sensing he was being tested, the president moved to pull the US out of the World Health Organization as part of the confrontation over the coronavirus. Among other moves, he also condemned China’s crackdown on Hong Kong and vowed to end favored treatment to the former British colony, saying the Communist Party had broken the treaty where it pledged to allow greater freedoms there.

Throughout his Rose Garden statement, the president’s language was notably more harsh toward China than it has been. He offered no warm words of friendship for President Xi Jinping, nor did he express confidence that the first part of the renegotiated trade deal would remain intact.

China is not backing down, with a top general threatening to attack Taiwan, which would force America to defend its tiny ally or see it crushed. China also threatened Australia’s economy, warning of a trade calamity if it sides with the United States.

Recall that China showed its willingness to meddle in our elections by commissioning anti-Trump articles and ads in the Midwest before the 2018 midterms, and we should expect more of the same as it tries to help defeat Trump and elect Biden. US officials also say Chinese hackers are engaged in cyber attacks against us and our allies.

It’s possible that some or all of these developments will break in Trump’s favor. The riots and looting, for example, are not likely to move independent voters to Biden, and becoming China’s preferred candidate might hurt him more than it helps. At the least, it will bring new focus to Hunter Biden’s business there.

Similarly, the opposition of Big Tech can be seen as another example of the media abandoning their standards to defeat Trump, and thus energize his supporters.

Still, the growing sense of chaos in the country is an unpredictable factor that could determine the November outcome. In about five months, we will know if President Houdini can pull off another great escape.

Andy’s ego is showing

Gov. Modesty had this to say about himself Friday:

“Nobody reopened New York City in history. Nobody closed New York City in history. That will be my claim to fame.”

Well, part of it. There are also the thousands upon thousands of nursing home residents who died after Cuomo ordered the homes to accept patients infected with the coronavirus.

That, too, will be part of his fame. Or rather, his infamy.

Why more say ‘Goodbye, NY’

The decline of New York, by the numbers.

The Post reports that a career criminal is using the idiotic bail laws to terrorize victims in a crime spree in which he was arrested 19 times — but is still walking free. The con, identified as Frank Pagan, was let go last month after allegedly threatening to kill his wife.

“I will burn your house down. I got grenades and I got shotguns. I’m going to shoot you in the head,” he said in a voicemail, prosecutors charge.

Meanwhile, The Wall Street Journal editorial page reports that cellphone data show that 15 percent of Manhattan residents have left.

With Cuomo in Albany, Mayor Putz in City Hall and Frank Pagan on the loose, they have reasons not to return.