Mr. Moore announced in June that he would run again next year.

News of Mr. Sessions’s decision to run startled and dismayed national Republicans, who had hoped that he would step aside to avoid the possibility of being vilified by Mr. Trump — and to spare them the headache of a nationalized race in a state they hope to win back.

Mr. Jones is one of the most vulnerable Democratic incumbents in the Senate, and Republicans have been counting on retaking his seat. Without it, their path to retaining their 53-to-47 majority in the chamber is more challenging.

Mitch McConnell, the Senate majority leader, has been less than thrilled with the idea of a Sessions candidacy, according to two people familiar with his thinking. He views it as a distraction that could end poorly for Republicans — especially if a crowded Republican primary ends with Mr. Moore as the nominee again.

Mr. Sessions had been chewing on the idea of returning to the Senate for several months, making clear to allies and advisers that he was pained at the possibility that his final act in public life could be his contentious 21-month tenure at the Justice Department. He had talked to aides and consultants, had polling conducted and asked friends whether they thought Mr. Trump might warm to him.

But over the last week, Mr. Trump sent word to Mr. Sessions through allies that he would publicly attack him if he ran. And Mr. McConnell recently approached Mr. Trump, asking him whether his feelings about Mr. Sessions might have improved. The president said he was very much still opposed to Mr. Sessions and would make that clear if he had to, according to a person briefed on the discussions.

Several Republican officials thought that had settled the matter — until Mr. Sessions decided to run.

Mr. Sessions’s decision comes just before the Friday deadline to enter the race. While he has massive name recognition, he has less cash on hand in his previous Senate account than Bradley Byrne, a congressman who represents a district near Mobile, public records show — a disadvantage that could prove challenging.