WASHINGTON — President Donald Trump announced Tuesday morning that he had fired Secretary of State Rex Tillerson and appointed CIA Director Mike Pompeo to replace him, ending months of speculation about how much longer the embattled Tillerson would last in the job.

In a tweet, Trump thanked Tillerson for his service and said Pompeo "will do a fantastic job."

Mike Pompeo, Director of the CIA, will become our new Secretary of State. He will do a fantastic job! Thank you to Rex Tillerson for his service! Gina Haspel will become the new Director of the CIA, and the first woman so chosen. Congratulations to all! — Donald J. Trump (@realDonaldTrump) March 13, 2018

The ouster ended months of discord between Trump and Tillerson, who often seemed out of the loop or in disagreement with the president on major foreign policy decisions. The president also named Gina Haspel as his choice to succeed Pompeo as head the CIA, pending the confirmation process in the Senate. Those hearings are expected to dredge up the debate over controversial interrogation tactics, like waterboarding, which could make her path to confirmation a rocky one.

Speaking to reporters at the State Department on Tuesday afternoon, a subdued Tillerson said he would be turning over all of his responsibilities to Deputy Secretary of State John Sullivan by the end of the day. He officially leaves his post at the end of March.

Tillerson said Trump had called him around noon Tuesday from Air Force One, while en route to California — several hours after the president had publicly announced Tillerson's firing on Twitter.

"What is most important is to ensure an orderly and smooth transition during a time that the country continues to face significant policy and national security challenges," Tillerson said during his brief remarks, which did not include any reference to Trump.

Tillerson did single out Russian aggression, a subject on which he and Trump had recently diverged.

"Much work remains to respond to the troubling behavior and actions on the part of the Russian government," Tillerson said. "Russia must assess carefully as to how its actions are in the best interest of the Russian people and the world more broadly. Continuing on their current trajectory is likely to lead to greater isolation on their part, a situation which is not in anyone's interest."

Trump's firing of Tillerson was just the most recent of many slights suffered by the former-businessman-turned-top-diplomat at the hands of his boss: A senior State Department official told NBC earlier Tuesday that Tillerson had officially learned of his firing when Trump tweeted the news.

The exit was not a voluntary one, the State Department confirmed in a startling statement Tuesday. Tillerson "did not speak to the president and is unaware of the reason" for his firing, Under Secretary of State Steve Goldstein said in a statement Tuesday morning, "but he is grateful for the opportunity to serve."

Hours after Goldstein's statement, he, too, was fired, a senior State Department official confirmed to NBC News. In a statement after his dismissal, Goldstein said he was "proud to speak on behalf of the secretary of state to the American people and allies throughout the world, and this has been the honor of a lifetime."

The White House and Foggy Bottom issued competing accounts Tuesday of the details of Tillerson's firing.

NBC News learned Tuesday from sources familiar with the situation that chief of staff John Kelly had spoken with Tillerson by phone on Friday and told him that Trump intended to ask him to “step aside." In that call — which came while Tillerson was on an official visit to Africa — Kelly did not specify when that change might come. Kelly also called Tillerson again on Saturday, a senior White House official said, expressing once again the president's "imminent" intention to replace him.

The Associated Press, citing senior State Department officials, reported Tuesday that Tillerson had been even more blindsided, saying that Kelly had warned him on that Friday call that there might be a tweet coming from the president that would concern him, but did not detail when or what it might say.

Tillerson, Goldstein said, had "every intention of staying because of the critical progress made in national security."

It's not the first time the president has opted for an indirect approach to firing government aides, avoiding face-to-face confrontation despite being well-known for his willingness to say "you're fired" on national television to contestants on the reality show, "The Apprentice."

His surprise dismissal of James Comey as FBI director came while Comey was in California, and his tweet announcing the departure of Reince Priebus as his chief of staff came while Trump was on Air Force One. Priebus was left on the tarmac at Andrews Air Force Base when the plane landed, after the news was out.

On the South Lawn Tuesday, Trump told reporters he was “close” to having the Cabinet he wanted, wishing Tillerson well while predicting “great” things from Pompeo at the State Department.

"Rex and I have been talking about this for a long time," the president said before boarding Marine One to head to California. While the two got along "well," Trump said, "we disagreed on things."

"We were not really thinking the same," Trump said of Tillerson. "With Mike ... we have a very similar thought process. I think it's going to go very well."

As for Tillerson, Trump said he thought "Rex will be much happier now."

Tillerson's is just the latest in a string of high profile departures from the Trump administration in the past month. Longtime Trump confidante Hope Hicks resigned as communications director at the end of February, while top economic advisor Gary Cohn announced his departure last week.

Though Tillerson's firing dominated headlines early Tuesday, it emerged that John McEntee — the president's longtime personal assistant and an original campaign member — had also left the administration. McEntee will take on a senior role within the Trump re-election campaign after abruptly exiting his White House job this week amid reports that he is under investigation by the Secret Service for financial crimes, according to federal law enforcement officials.

And more departures could be coming. NBC reported this month that national security advisor H.R. McMaster would most likely be out of his job by the end of the month, with the White House pushing back on the story.

Pompeo may also face a tough confirmation process in the Senate to succeed Tillerson.

While Tillerson took a more traditional approach to his job as America's top diplomat than Trump appeared comfortable with, clashing with the president throughout his tenure, Pompeo has enjoyed a much closer relationship with Trump. Current and former intelligence officials told NBC last year that some inside the intelligence community had started calling Pompeo the “Trump whisperer,” a reference to the depth of their relationship.

Tillerson returned from his Africa trip a day early, landing early Tuesday morning in Washington.

During Tillerson's absence from Washington, even more daylight appeared between him and his boss, most recently on North Korea, but also on the recent poisoning of a former Russian double-agent in Britain last week.

While the White House on Monday refused to sign on to British assessments that Russia was responsible for the poisoning, Tillerson, speaking to reporters aboard his government plane, referred to the attack as a “really egregious act” that appeared to have “clearly” come from Russia.

Trump's planned meeting with North Korea’s Kim Jong Un also played a role, a senior administration official told NBC News, saying that Trump “wanted to make sure to have his new team in place in advance of the upcoming talks with North Korea and various ongoing trade negotiations.” Trump said Tuesday that he had made the decision to speak with Kim by himself.

The day before Trump announced his decision to meet Kim last week, Tillerson, who was in Africa, said the two countries were still “a long way” from direct negotiations on the North's nuclear program.

Though the timing of the Tillerson ouster may have been a surprise, the move itself had been rumored for months.

A White House official told NBC News in December that the administration was considering a plan to replace Tillerson with Pompeo. At the time, the official said Tillerson’s allies within the administration had grown scarce — “he’d burned all his bridges,” this person said on the condition of anonymity.

The tension between Tillerson and Trump was heightened after NBC News reported last year that the secretary of state, a former chief executive of Exxon Mobile, had referred to the president as a “moron” after a July 20, 2017, meeting at the Pentagon, according to three officials familiar with the incident.

As has become somewhat standard practice for the president when he's considering staff changes, Trump fielded opinions on Tillerson for months from friends and outside advisers. One such person was top GOP fundraiser Elliott Broidy, who summarized a meeting he had with Trump last year in an email recently obtained by NBC News.

"President Trump asked me for my opinion of about the job Rex was doing," the email states. "I responded that Rex was performing poorly and should be fired at a politically convenient time. The president asked me why; to which I responded that Rex was frequently working at cross purposes and not following the president' policies. President Trump nodded at my comment with regard to Rex."

John Brennan, a former CIA director and now an NBC analyst, predicted that Haspel's nomination would get "close scrutiny" in the Senate given her years of work at the agency, including time spent running a prison in Thailand that used rough interrogation tactics, including waterboarding, on terror suspects — a practice Trump has voiced support for in the past.

And Pompeo's past comments on Russia, which have often echoed Trump's less-critical take, are also certain to be a central line of questioning for Republicans and Democrats alike in confirmation hearings.

For now, the Pompeo and Haspel nominations were earning Trump praise from Senate Republicans, including Tom Cotton of Arkansas, who supported both nominees on Twitter almost immediately after the announcement. NBC was told last year that the administration was considering Cotton for the top spot at the CIA.

A source close to Cotton told NBC on Tuesday that he was aware of the shakeup before the president's early morning tweet, giving him more notice than most of his fellow senators — and even the secretary of state himself.