Washington (CNN) When things were particularly bad between President Donald Trump and Jeff Sessions, the attorney general's chief of staff, Matt Whitaker, would attend White House meetings in his place.

But Sessions did not know that Whitaker at the same time was angling for a promotion.

Whitaker, who was installed at the Justice Department by powerful White House allies, "spoke and behaved like he was attorney general," a source with knowledge of the meetings said.

Wednesday, Whitaker got the job when Trump made him acting attorney general.

Trump's move puts Whitaker in charge of special counsel Robert Mueller's Russia investigation. It has also created new controversies, with legal experts debating about the legality of the appointment and news stories featuring his past criticisms of Mueller and defense of Trump.

The transformation of Sessions from influential early backer of Trump's improbable presidential campaign to frequent target of the President's scorn is a study in the fickleness of political alliances in Washington.

On Wednesday, the attorney general received the call everyone in Washington knew was coming some day soon.

John Kelly, the White House chief of staff, asked Sessions to submit his resignation, according to multiple sources briefed on the call. Sessions agreed to comply, but he wanted a few more days before the resignation would become effective. Kelly said he'd consult the President.

Soon, the sources say, top Justice officials convened on the 5th floor suite of offices for the attorney general. Eventually, there were two huddles in separate offices. Among those in Sessions' office was Deputy Attorney General Rod Rosenstein, his deputy Ed O'Callaghan, Solicitor General Noel Francisco and Steven Engel, who heads the Office of Legal Counsel.

A few yards away, Whitaker strategized with other aides, including Gary Barnett, now his chief of staff.

The rival huddles, which haven't been previously reported, laid bare a break in the relationship between Sessions and Whitaker that had emerged in recent weeks, after it became clear that Whitaker played a behind-the-scenes role in an aborted effort to oust Rosenstein.

A source close to Sessions says that the former attorney general realized that Whitaker was "self-dealing" after reports surfaced in September that Whitaker had spoken with Kelly and had discussed plans to become the No. 2 at the Justice Department if Rosenstein was forced to resign.

In recent months, with his relationship with the President at a new low, Sessions skipped several so-called principals meetings that he was slated to attend as a key member of the Cabinet. A source close to Sessions says that neither the attorney general nor Trump thought it was a good idea for Sessions to be at the White House, so he sent surrogates. Whitaker was one of them.

But Sessions did not realize Whitaker was having conversations with the White House about his future until the news broke in late September about Rosenstein.

On Wednesday as aides began drafting Sessions' resignation letter, the distrust for Whitaker burst into the open.

The fact that Whitaker would become acting attorney general, passing over Rosenstein suddenly raised concerns about the impact on the most high-profile investigation in the Justice Department, the Russia probe led by Mueller. The Mueller probe has been at the center of Trump's ire directed at Sessions and the Justice Department. Whitaker has made comments criticizing Mueller's investigation and Rosenstein's oversight of it, and has questioned the allegations of Russian interference.

Rosenstein and O'Callaghan, the highest-ranked officials handling day-to-day oversight of Mueller's investigation, urged Sessions to delay the effective date of his resignation.

Soon, Whitaker strode into Sessions' office and asked to speak one-on-one to the attorney general; the others left the two men alone. It was a brief conversation. Shortly after, Sessions told his huddle that his resignation would be effective that day.

O'Callaghan had tried to appeal to Sessions, noting that he hadn't heard back about whether the President would allow a delay. At least one Justice official in the room mentioned that there would be legal questions about whether Whitaker's appointment as acting attorney general is constitutional. Someone also reminded Sessions that the last time Whitaker played a role in a purported resignation -- a few weeks earlier in September, with Rosenstein -- the plan collapsed.

Sessions never heard in person from the President -- the man who gained television fame for his catch-phrase "You're fired" doesn't actually like such confrontation and prefers to have others do the firing, people close to the President say. Kelly called Sessions a second time to tell him the President had rejected his request for a delay.

The Justice Department declined to comment for this story.

JUST WATCHED Despite denial, Trump said last month he knows Whitaker Replay More Videos ... MUST WATCH Despite denial, Trump said last month he knows Whitaker 04:07

Whitaker at DOJ

Whitaker and Sessions didn't have a prior relationship before Sessions -- at the urging of the White House -- accepted Whitaker as his chief of staff. Sessions interviewed him and the two grew to have a good working relationship. Sessions liked him, but even if he didn't, the plan was already hatched for him to take the role, according to one source familiar with the matter.

Leonard Leo, the influential executive vice president of the Federalist Society, recommended to then-White House counsel Don McGahn that Whitaker would make a good chief of staff for Sessions.

"I recommended him and was very supportive of him for chief of staff for very specific reasons," Leo said Friday.

"Jeff Sessions needed a reliable conservative, a strong manager, and someone who had credibility who had previously served the department," he added. "Whitaker was a very good former US attorney and is a very good manager. He's a no-nonsense, get-it-done kind of guy."

Whitaker, a 49-year-old former U.S. attorney from Iowa and former CNN contributor, is a gregarious imposing presence that fits his former life as college football tight end. His Twitter feed, which he made private in recent days, shows a picture of him weightlifting, a passion he complains he doesn't get as much time to enjoy these days.

On Thursday, his first full day as acting attorney general, and with criticism of his appointment beginning to swirl, he tried to exude a calm demeanor. He convened a late afternoon meeting with senior department officials. He kept remarks brief, saying he was proud to lead them, that they've been doing good work and to keep doing what they're doing. Another call, also brief, with US attorneys around the country followed.

On Friday, he sent his first department-wide message, thanking Sessions for his service and extolling the work of colleagues around the country. "As we move forward, I am committed to leading a fair Department with the highest ethical standards, that upholds the rule of law, and seeks justice for all Americans," Whitaker wrote.

Sessions' last day

The ignominious end to Sessions' tenure is a far cry from the early days of the 2016 campaign, when he became an eager surrogate. Sessions' hardline views on immigration became suffused in the rhetoric that Trump adopted.

Sessions was the first US senator to endorse Trump at a time when establishment Republicans were still staying away, and he left his safe Alabama Senate seat to take the attorney general job.

Several members of his staff also joined the President's team, helping to craft some of the harsh immigration policies that Sessions often preached from Capitol Hill and which have become a cornerstone of stump speeches that Trump regularly uses to excite his political base.

But months into the job, Trump had soured on Sessions for the sin of recusing himself from the federal investigation into Russian interference in the 2016 elections and possible connections to the Trump campaign.

More recently, Sessions appeared at peace with the prospect of being ousted from office. He made a series of valedictory visits with law enforcement around the country, seeking to underline what he believes will be his legacy of strong support for law enforcement and efforts to reduce crime.

Sessions spent Election Day on Tuesday surrounded by what he loves: cops and sweets.

He visited the FBI's laboratory in Quantico, Virginia, where officials warmly greeted him and provided a briefing on their latest capabilities.

Over a plate of Milano cookies, he was an engaged questioner asking a scientist about DNA identification and how it has affected guilty pleas in court.

Later, when he arrived in the cafeteria for lunch, a room full of FBI personnel and local police officers training in the National Academy rose to their feet as he entered the room. He went around from table to table, shaking hands, posing for pictures -- soaking up the moment and capping it off with vanilla ice cream with sprinkles.

Roughly 24 hours later, he was out of a job.