WASHINGTON (Reuters) - In backing Roy Moore in Alabama’s U.S. Senate race even though the candidate faced allegations of sexual misconduct with teenage girls, President Donald Trump made a risky bet - and lost big.

U.S. President Donald Trump gestures as he arrives for a rally in Pensacola, Florida, U.S., December 8, 2017. REUTERS/Carlo Allegri

The victory by Democrat Doug Jones over the Republican Moore in the Alabama special election on Tuesday was a catastrophe for Trump, portending a Democratic wave next year that could cost Republicans control of one or both houses of Congress.

The stakes in Alabama were that high. Democrats already were confident they had a strong chance to retake the U.S. House of Representatives in next year’s congressional elections. Jones’ narrow victory increases their once-long odds of retaking control of the Senate as well.

If Democrats were to recapture both chambers, they would serve as a check on Trump’s agenda and might even initiate impeachment proceedings against him.

“That Republicans lost in one of the most Republican states in the nation is a wake-up call no matter how flawed their candidate was,” said Jesse Ferguson, a Democratic strategist and former aide to Democrat Hillary Clinton’s presidential campaign.

Democrats never expected to have a chance in Alabama, where they had not won a U.S. Senate race in 25 years. But the combination of Trump’s unpopularity, the sexual misconduct allegations that erupted against Moore in November, and Trump’s enthusiastic support of him anyway gave them the opportunity, experts said.

“Trump was the one who got Jones within firing range, and Moore allowed Jones to win,” said Kyle Kondik, a political analyst at the University of Virginia.

Even as Democrats lost several special congressional elections this year, they consistently showed higher levels of turnout and engagement, which is attributable to Trump, Kondik said.

TRUMP REFERENDUM?

The Alabama race showed there were limits both to Trump’s endorsement power and his judgment.

Even as senior Republicans urged Trump to abandon Moore, the president decided instead in the campaign’s final days to throw the full weight of his office behind him. In the end, that was not enough, and early turnout reports suggested that many Republicans stayed home.

Moreover, despite the sexual misconduct allegations against Moore, the race near the end increasingly seemed to become about the president. Moore’s camp this week said the contest was specifically a referendum on Trump and his presidency.

“It is Donald Trump on trial in Alabama,” Dean Young, a strategist for Moore, told ABC News.

Trump congratulated Jones on Twitter “on a hard fought victory” and added: “Republicans will have another shot at this seat in a very short period of time.”

The loss was also a body blow to Steve Bannon, Trump’s former top strategist, who backed Moore in the primary against the Republican incumbent, Luther Strange, because he viewed Moore as a more reliable ally.

Bannon also frequently characterized the race as less about Alabama and more about furthering Trump’s economic nationalist agenda.

Bannon is looking to wage an insurgency against the Republican establishment in the 2018 congressional elections, particularly Senate Majority Leader Mitch McConnell, who condemned Moore after several women accused him of unwanted sexual contact when they were in their teens and he was in his 30s.

Moore, 70, has denied the allegations, and Reuters has not independently verified them.

ANTI-ESTABLISHMENT

Beyond Moore, Bannon is supporting anti-establishment 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.

Bannon also may ultimately support challenges against sitting Republicans in Mississippi and Wyoming.

But Moore’s loss seems certain to dampen that effort, and Republicans who fear losing control of Congress may be even less likely to back outsider candidates who may turn off mainstream voters.

It is now an open question whether Trump will inject himself into more Republican primaries, given his setback in Alabama.

“When you nominate candidates who are unqualified and an embarrassment to the party, you run the risk of ruining your entire brand,” said Josh Holmes, a Republican consultant and close ally of McConnell.

Bannon’s supporters say rank-and-file Republican voters are more likely to blame McConnell, not Bannon, for the loss in Alabama, arguing that McConnell and his well-resourced Senate Leadership Fund did nothing to help Moore.

McConnell “actively opposed the Republican candidate in Alabama and threatened our Senate majority by helping to put a liberal Democrat in that seat,” said Andy Surabian, a former Bannon protégé who now advises a pro-Trump advocacy group, Great America Alliance.

Even with the Alabama win, Democrats face a significant challenge next year if they are to take control of the Senate. They must defend 10 incumbents in states that were won by Trump and they must gain two seats currently held by Republicans. Their best opportunities to secure those seats lie in Arizona and Nevada, and perhaps Tennessee.

Democrats need 24 seats to retake the House, but that is viewed as a more realistic goal because of the number of congressional districts where they are competitive, particularly in suburban areas.

Brian Walsh, president of another pro-Trump group, America First Policies, said Trump could not be blamed for Moore’s loss, arguing that the president’s late endorsement almost won the race for Moore, a deeply flawed candidate.

“He was trying to push a boulder up a hill,” Walsh said.