It was Meghan McCain, the daughter of Senator John McCain, who summed up the feelings of many in a three-word tweet: “Suck it, Bannon.”

This moment had been a long time coming. The hardline nationalist, who helped mastermind Donald Trump’s election victory, brought his blow-everything-up philosophy to the White House then returned to rightwing Breitbart News, had finally got his comeuppance.

The Republicans’ stunning reversal in Alabama on Tuesday was a defeat for the candidate and alleged child molester Roy Moore, a defeat for the president, Donald Trump, but, above all, a defeat for Steve Bannon.

“Bad night for a lot of people, but mostly for Steve Bannon,” the Republican strategist Bruce Haynes tweeted. “He’ll be blamed (rightly so) supporting a terriblehorrible candidate, for poor judgment, awful last minute comments and for dragging the president into a losing race.”

The former investment banker and White House chief strategist apparently thought he could do for Moore what he did for Trump in last year’s presidential election. He cast the race as less about Alabama than about furthering Trump’s economic nationalist agenda. In the Republican primary he defied the president himself, who endorsed Luther Strange. Moore won that contest and Bannon dived in with both feet.

It was only this Monday that his biographer, Joshua Green, wrote an article for Bloomberg headlined: “How Steve Bannon Rescued Roy Moore’s Campaign Against All Odds.”

Green noted that by 14 November, facing multiple allegations of sexual misconduct with teenagers reported in the Washington Post, Moore had been abandoned by the Republican party and was at risk of losing the Trump cheerleader and Fox News host Sean Hannity.

Bannon recognised that this would probably be fatal. According to Green, he asked Hannity not to call on Moore to withdraw and instead to let Alabama voters decide. A source said Hannity texted one of Bannon’s Breitbart colleagues: “You pull this off it’s a f--- miracle.”

Bannon, who has branded the media the opposition party, is also said to have sent Breitbart reporters to Alabama in an effort to discredit the Washington Post story, or at least kick up enough dust to cause confusion.

By election day, the strategy appeared to have worked. Bannon had persuaded Hannity to back down, Trump to endorse and the Republican national committee to restore funding. Mitch McConnell, the Senate majority leader, muted his past calls for Moore to step aside, saying the people of Alabama should decide.

But in the end, all Bannon’s efforts, including a speech at a campaign rally on the eve of the election (“There’s a special place in hell for Republicans who should know better”), were in vain. Backed by women and African Americans in particular, Democrats enjoyed their first Senate victory in a quarter of a century in Alabama, a Republican bastion in the deep south where Trump beat Hillary Clinton by 28 percentage points.

Josh Holmes, a former chief of staff to McConnell, tweeted: “I’d just like to thank Steve Bannon for showing us how to lose the reddest state in the union.”

The party backlash was swift and vicious. Steven Law, head of the pro-McConnell Senate Leadership Fund, said: “This is a brutal reminder that candidate quality matters regardless of where you are running. Not only did Steve Bannon cost us a critical Senate seat in one of the most Republican states in the country, but he also dragged the president of the United States into his fiasco.”

Bannon had been plotting an insurgency against the Republican establishment in the 2018 congressional elections, supporting primary candidates such as Kelli Ward in Arizona, Danny Tarkanian in Nevada and Kevin Nicholson in Wisconsin, all of whom oppose McConnell staying on as Senate leader.

But suddenly the emperor has no clothes and all is in doubt. There is less and less reason to believe that Trump’s electoral success can be replicated by “mini-Trumps” at a local level. Bannon, so used to attacking, may suddenly find himself playing defence.

Rich Lowry, editor of National Review, tweeted: “Lesson for the GOP: if there is a bridge too far in Alabama, there is a bridge too far in every other state where Steve Bannon wants to run a fringy candidate.”

Some felt that, by losing, Republicans had won, coming one step closer to getting Bannon out their system, rejecting extremism in favour of moderation. The former senator Norm Coleman wrote: “Short-term pain, long-term gain. Roy Moore and Steve Bannon losing tonight is big win for the GOP. We will survive 2 years of D. Jones. Moore would have buried GOP in 2018.”

The president, however, still casts a long shadow.