To hear the media tell it, Donald Trump was finished last week.

For calling a first-generation judge of Mexican heritage a “Mexican,” he had injected racism into the campaign. For firing his strong-arm campaign manager, Corey Lewandowski, he admitted his insurgency was adrift. For not raising as much cash as a woman who’s effectively been running for president since 1992, he was a hopeless, incompetent amateur. And, oh yes — he was down in the polls.

In sum, for not playing by the rules laid down by consultants and political journalists, Trump was derailed, wrecked, finished.

And then things changed.

Having consistently proven the masters of conventional wisdom wrong — not only naysaying Democrats but also preening “NeverTrumpers” — The Donald once again confounded his critics with a disciplined speech on Wednesday, laying out the air-tight case against Hillary Clinton by hitting her right where she mistakenly thinks she’s strongest: her foreign-policy record as secretary of state..He pounded her deadly miscalculation in Libya, which resulted in four dead Americans at Benghazi, her role in the rise of ISIS and her cozy financial relationships and personal enrichment via the Clinton Foundation with sworn enemies of America. It was a boffo new beginning.

And then, as if to make Trump’s point that we need a radical break from DC-as-usual, along came Brexit, Britain’s poll-defying plebiscite to leave the European Union and regain its national independence.

So here’s what Trump must do now to capitalize on his newfound mojo and win in November:

First, keep pummeling Hillary. The only presidential candidate in history to run while under federal investigation, Clinton has benefited from chummy relationships with media pooh-bahs who have successfully shielded her for decades. But the former first lady has a thin skin and a glass jaw; she’s never faced sustained, fearless criticism before and doesn’t handle it well.

Her brazen defiance of federal regulations, State Department protocols, national-security concerns and espionage and bribery laws make her the tomato can of candidates. Heck, the guy who set up her private e-mail server just took the Fifth 125 times in a deposition. Think he’s got something to hide?

Second, learn a lesson from John McCain and Mitt Romney. The Maverick was a media darling until he had the effrontery to run against The One in 2008, while Romney was transformed from a successful Mormon businessman into a rapacious ogre. Overwhelmingly Democratic and partisan, the media votes with its pens and cameras every day during campaign season.

Much of Trump’s early appeal derived from his combative relationship with reporters, whom he not only doesn’t fear but treats with overt contempt. He should keep doing it. As Churchill said about the Germans, “The Hun is always either at your throat or at your feet.” So’s the media. Like Hillary (who largely shuns the press), Trump should control his availability, answer the questions he likes, turn around the questions he doesn’t, and leave.

Third, skip the “gotcha” game. During one of the GOP debates, Trump filibustered a response to radio host Hugh Hewitt’s question about the three legs of the “nuclear triad” because he didn’t know what that phrase meant (subs, bombers, missiles). But that’s the sort of thing instantly explained and learned. After all, he’s a first-time candidate navigating an ocean of wonks who think they alone should decide the qualifications necessary to become president.

A presidential campaign is not a quiz show, so the next time Trump’s confronted with unfamiliar Beltway jargon he should just ask for clarification, answer the question forthrightly and move on.

Fourth, make it clear to the junior wing of the Permanent Bipartisan Fusion Party who’s boss now. Despite its success in the congressional elections of 2010 and ’14, the GOP has been whining it can’t shape policy without holding the White House, too. Here’s their big chance.

The center-right public is outraged at the Republicans’ largely ineffective opposition to Democrat progressivism and executive overreach. Let’s hope last week’s Supreme Court decision blocking Obama’s amnesty for illegals — and the Democrats’ childish sit-in in the House — will stiffen GOP “leadership” spines. But if not, Trump should do it by actually leading.

Finally, be yourself — but better. Trump walks, talks and acts like the quintessential guy from Queens, from his un-pukka accent to his stream-of-consciousness barroom bluster. He’s that anomaly, a rich man with a peasant’s taste for shiny material things.

Now it’s time for Trump 2.0: the focused, disciplined candidate we saw last week. This means focusing on Hillary’s weaknesses without fear, bringing speaker Paul Ryan and majority leader Mitch McConnell to heel and staying on message to Make America Great Again.

Hey, if the Brits can say adieu to the European Union and defy their entire political establishment, can Americans do any less? Across the world, there’s a hunger for national greatness again — and if Beltway insiders don’t hear that message now, they surely will in November.

Michael Walsh is an author and screenwriter who blogs regularly at PJ Media.