WASHINGTON — Sue Gordon, a career CIA official who is serving as the principal deputy director of national intelligence, told the White House she would leave her job today after she learned she would be passed over as director of national intelligence, according to a source with direct knowledge of the matter.

President Donald Trump confirmed that Gordon would be leaving on Twitter this evening, not long after Bloomberg News was the first to report her departure.

Trump said Gordon had announced she would be leaving on Aug. 15, and called her "a great professional with a long and distinguished career" for whom he had "developed great respect." In a second tweet, he said her departure coincided with the retirement of Director of National Intelligence Dan Coats, whose planned exit on Aug. 15 was previously announced.

Trump named Joseph Maguire, who currently serves as the Director of the National Counterterrorism Center, as acting director of national intelligence.

More from NBC News:

The source with direct knowledge told NBC News that Coats had recommended that Gordon replace him, but that White House Chief of Staff Mick Mulvaney told him they had someone else in mind.

Trump tweet 1

When Coats told that to Gordon, she felt she had no choice but to hand in her resignation, the source said.

Her departure may raise the hackles of both Republican and Democratic senators, who supported her vigorously. The source said she recently had assured Sen. Richard Burr, R-N.C., chairman of the Senate Intelligence Committee, and Sen. Mark Warner of Virginia, the ranking Democrat on the committee, that she would stay on and serve as acting DNI.

In a statement to NBC News, Warner praised Gordon's tenure and called her departure "a great loss not only to the intelligence community, but to the country." He also sharply criticized Trump.

"President Trump has repeatedly demonstrated that he is seemingly incapable of hearing facts that contradict his own views," Warner said. "The mission of the intelligence community is to speak truth to power; Yet in pushing out two dedicated public servants in as many weeks, once again the President has shown that he has no problem prioritizing his political ego even if it comes at the expense of our national security."

Burr said in a statement, "Sue Gordon's retirement is a significant loss for our Intelligence Community. In more than three decades of public service, Sue earned the respect and admiration of her colleagues with her patriotism and vision. She has been a stalwart partner to the Senate Intelligence Committee, and I will miss her candor and deep knowledge of the issues. I look forward to seeing what new challenges she will tackle next."

Trump had previously hoped to install Rep. John Ratcliffe, R-Tex., as DNI, but Ratcliffe's nomination was withdrawnafter an NBC News report that he had overstated his experience prosecuting terrorism and amid objections from members of Congress from both parties.

Gordon started with the CIA in the 1980s. Earlier in this decade she was CIA director of support, and then became the CIA's first cyber czar in 2013. She was named to her current post in January 2015 by President Barack Obama.

Following Ratcliffe's withdrawal, a bipartisan push began to emerge in support of Gordon, who is widely respected both on Capitol Hill and in the president's orbit for her decades of experience in the intelligence community.

While one current and one former U.S. official familiar with the matter say the White House had been planning to prevent Gordon from stepping into Coats's role in an acting capacity, the president seemed to warm to the idea.

"Sue Gordon is there now and I like her very much," he said on Friday. "Certainly she will be considered for the acting [job.]"

Coats and Gordon oversaw the country's intelligence community, including the Central Intelligence Agency and National Security Agency, and acted as an adviser to the president on national security and intelligence matters.