But aides said that Mr. Trump might still fault others for the loss. The list of those who might be the targets of his ire include the Senate majority leader, Mitch McConnell, Republican of Kentucky, whose advisers pressed the president to back Senator Luther Strange in the primary, only to see him lose. One of the advisers said that Mr. Trump would still nurse a grudge against Mr. McConnell, whose instincts the president does not trust, for leading him to the original endorsement.
Those advisers said the president was troubled watching a stream of Republicans step away from Mr. Moore over decades-old allegations of sexual misconduct with teenagers, and he did not want to join the stampede.
Instead, the president threw the full weight of his office and reputation behind Mr. Moore.
White House aides were also bracing for the president’s reaction toward Stephen K. Bannon, his former chief strategist who had publicly said Mr. Trump’s base was with Mr. Moore and suggested the movement would march on without the leader of the party. Mr. Bannon’s continuing sway over Mr. Trump has deeply bothered the advisers still on the government payroll, and they were optimistic that the outcome in Alabama would weaken his grip.
Mr. Trump’s first reaction to the Democratic Party’s win — which he absorbed while in the White House residence, alone for much of the evening, with the first lady out of town — was a demure Twitter post congratulating Doug Jones.
“A win is a win,” Mr. Trump wrote, adding that Republicans would have another chance at the seat — vacated by Jeff Sessions, now the attorney general — soon enough. It was a surprisingly gracious tweet from a president who had excoriated Democrats, attacked Mr. Jones and insisted Republicans needed the vote from Alabama in a string of statements over the past week.
The president’s aides spun the loss as belonging squarely to Mr. Moore. Mr. Moore had been accused of sexual assault and child molestation by a number of women, one of whom said she was just 14 at the time he made sexual contact with her. Mr. Moore was a weak candidate, White House officials argued, and Mr. Trump could not drag someone that weak over the finish line against a crush of outside spending and a bipartisan message from Mr. Jones.
In private conversations, several West Wing advisers noted that the vote for a tax code revamp was expected to take place before Mr. Jones is sworn in. A victory on the tax bill would provide the president with a quick opportunity to change the subject.
But in the search for scapegoats, Bill Stepien, the White House political director who has been under fire from some of his colleagues, could also be a target. John F. Kelly, the White House chief of staff, is a political neophyte who relies on others, and he has told people the political staff needs beefing up.
Some of the president’s aides had told him the polling in Alabama was unreliable, and it was hard to know who would actually show up to vote.
But Mr. Bannon’s words rolled round the president’s mind for several days before his endorsement. The president was also enraged when his daughter Ivanka Trump got ahead of him by declaring there was a “special place in hell” for people who harm children.
Mr. Bannon jabbed at Ms. Trump on Monday night at a rally in Alabama for that line.
One White House adviser said that Mr. Trump was unlikely to blame his daughter. But he would almost certainly blame someone.
Still, the embarrassing loss showed the limits of the president’s power to persuade voters and to lead his party.
But, as he so often does, Mr. Trump quickly moved to try to redefine the outcome in a more favorable light.
The president had placed his credibility and the weight of his office behind Mr. Moore, a deeply flawed Senate candidate who had been rejected by a clear majority of Republican elected officials, but had been propped up by the endorsement of Mr. Trump and the backing of Mr. Bannon.
Mr. Moore lost in a state that Mr. Trump had won by 28 points over Hillary Clinton in 2016, a state where the Democratic Party had been essentially moribund for decades. The president endorsed Mr. Moore against the advice of some of the White House and nearly every Republican member of Congress. He stumped for him at a rally in nearby Pensacola, Fla., last week, and recorded telephone messages sent to thousands of Alabama voters.