WASHINGTON — President Donald Trump backed Roy Moore on Tuesday, breaking with national Republican leaders and reaffirming his support nearly two weeks after the Senate candidate from Alabama was accused of sexual advances against teenage girls years ago.

“He totally denies it. He says it didn’t happen,” Trump told reporters as he left the White House to spend Thanksgiving at his Mar-a-Lago estate in Florida. “I do have to say, 40 years is a long time.”

The president’s statements of doubt about Moore’s accusers, and his suggestion he might campaign for Moore, came days after many party leaders broke with the nominee. The Republican National Committee withdrew its support last week, following the Senate Republicans’ campaign committee, and both Senate Majority Leader Mitch McConnell and House Speaker Paul D. Ryan have called on Moore to step aside.

“I believe the women, yes,” McConnell told reporters in Kentucky more than a week ago. He said Moore is “obviously not fit to be in the Senate,” suggesting that Senate Republicans could refuse to seat Moore or expel him.

“These allegations are credible,” Ryan said, adding, “He should step aside.”

Similarly, two prominent Alabama Republicans — Jeff Sessions, who gave up the Senate seat in contention to become Trump’s attorney general, and longtime Sen. Richard C. Shelby — said they believed the accusers. Shelby said he would “absolutely not” vote for Moore, but instead would write in some Republican’s name.

McConnell had expressed hope while Trump was in Asia earlier this month that the president, upon his return, would press Moore to leave the race, and the president indicated he would address the matter. But for the last week he dodged reporters’ questions, reflecting the awkwardness of his own history of alleged sexual misbehavior. Press Secretary Sarah Huckabee Sanders said repeatedly that Alabama voters should decide Moore’s fate.

With his long-anticipated comments Tuesday, Trump echoed some Moore supporters, including Alabama Gov. Kay Ivey, who put partisan concerns above the character issues surrounding Moore. They argue that a Republican senator is needed to support Trump’s agenda and judicial nominees.

Polls show Moore in a tight race with Democrat Doug Jones ahead of the Dec. 12 special election, but the Republican has lost significant ground in the solidly conservative state.

“I can tell you one thing for sure. We don’t need a liberal person in there, a Democrat — Jones,” Trump said. “I’ve looked at his record. It’s terrible on crime. It’s terrible on the border. It’s terrible on the military.”

Trump left the door open for campaigning for Moore. “I’ll be letting you know next week,” he said.

Moore continues to have strong backing from some of the anti-establisment Republicans who form the president’s political base. Breitbart, the news site controlled by former Trump adviser Stephen K. Bannon, sent reporters to Alabama in an effort to discredit The Washington Post’s reporting that revealed allegations of Moore’s sexual advances on teenage girls when he was a prominent local attorney in his early 30s. Breitbart’s attempts were not successful.

The Moore campaign quickly seized on Trump’s remarks attacking Jones and circulated a video of the president speaking. Trump’s comments could play a major role in the Senate election, said Carl Grafton, an emeritus political scientist at Auburn University at Montgomery.

“When I got into the barber shop — not a styling salon but a barber shop — it is 100 percent pro-Trump and has been since about an hour after he was elected,” Grafton said.

Speaking of Trump, he added, “Everyone has their qualifiers when they talk about him — how his language is not so so good, or this that or the other — but he’s as popular as Reagan was” among white middle-class and working-class voters.

Trump’s backing “provides people who don’t like Roy Moore, for whatever reason, an excuse to vote for him,” Grafton said.

K.B. Forbes, a Republican strategist in Birmingham who is running an anti-Moore political action committee, Save Alabama Now, said, “It is an abomination, in that we’re putting politics over principle.”

“Roy Moore is an alleged pedophile who targeted teenage girls and he will become the poster child for all the opponents of the Republican Party,” Forbes added.

The issue of sexual misconduct, with recent complaints against dozens of well-known men in business, entertainment, the media and politics, has revived allegations against Trump that nearly derailed his campaign last year, when more than a dozen women accused him of sexually inappropriate behavior.

Despite Trump’s choice to believe Moore’s denials over the accusations of multiple women, the president sought to be sympathetic to women generally amid the national debate over sexual harassment.

“Women are very special,” he said. “I think it’s a very special time. A lot of things are coming out and I think that’s good for our society and I think it’s very, very good for women.”

Trump had previously criticized Minnesota Sen. Al Franken, a Democrat, who was accused of groping a woman during a 2006 USO tour and grabbing a woman’s buttocks in 2010 at the Minnesota State Fair.

Trump was circumspect Tuesday when asked whether Franken should resign from the Senate.

“I don’t know,” he said. “Look, I don’t want to speak for Al Franken. I don’t know what happened.”