U.S. President Donald Trump demanded that the New York Times reveal the identity of a senior official who wrote an anonymous op-ed in the newspaper claiming that key members of the administration were secretly working against him.

In a Wednesday night tweet, Trump lashed out at the Times over the article’s publication, questioning whether the author even existed and citing national security as a reason for the newspaper to disclose the person’s name, according to Bloomberg.

"If the GUTLESS anonymous person does indeed exist, the Times must, for National Security purposes, turn him/her over to government at once!" Trump said on Twitter.

The writer, identified by the Times only as a senior administration official, said that he or she, and others in government, have vowed to thwart the president’s “more misguided impulses until he is out of office.”

“The root of the problem is the president’s amorality,” the person wrote. “Anyone who works with him knows he is not moored to any discernible first principles that guide his decision making.”

Trump had condemned the op-ed almost as soon as it was published, in person and on Twitter. He called it "a disgrace” and the writer “gutless” during an event with sheriffs at the White House on Wednesday afternoon. The official is “probably here for all the wrong reasons,” Trump continued, and then vowed that he would win re-election in 2020.

Read alsoMueller to accept Trump's written responses in Russia probe as first step - Reuters

On Wednesday evening, before demanding that the Times unmask the writer, Trump tweeted one word: “TREASON?”

The Times said in a note appended to the op-ed that it knew the author’s identity but that “publishing this essay anonymously is the only way to deliver an important perspective to our readers.” The writer indicated that he or she is a political appointee, not a career civil servant -- a class of federal employees that some Trump allies have long derided as a “deep state” set on undermining him.

Late Wednesday night, Trump again took to Twitter to tell his followers, "I’m draining the Swamp, and the Swamp is trying to fight back. Don’t worry, we will win!"

In the op-ed, the writer said that “ours is not the popular ‘resistance’ of the left,” and cited “bright spots” of Trump’s tenure, including deregulation, tax reform and increased military spending.

“But these successes have come despite — not because of — the president’s leadership style, which is impetuous, adversarial, petty and ineffective,” the person wrote.

Read alsoTrump targets Bloomberg after comments on Canada talks leaked

The reaction inside the White House on Wednesday afternoon ranged from shock to disbelief to frustration. The op-ed marked another setback for a West Wing already battered by a litany of recent controversies that have left some aides demoralized. But some also expressed a desire to pull together and counter those who want to exacerbate the sense of mistrust.

The op-ed appeared just a day after excerpts of journalist Bob Woodward’s latest book were published, portraying a West Wing in chaos and quoting senior officials disparaging Trump’s leadership and competence. Woodward’s book followed the funeral of Senator John McCain -- hailed as an American hero and Republican icon -- where the president was unwelcome. Meanwhile, the White House was still reeling from the guilty plea of Michael Cohen, the president’s former lawyer, and the conviction of Paul Manafort, Trump’s former campaign manager, on Aug. 21.

White House press secretary Sarah Huckabee Sanders said in a statement that the author of the op-ed should step down.

“The individual behind this piece has chosen to deceive, rather than support, the duly elected President of the United States,” Sanders said. “He is not putting country first, but putting himself and his ego ahead of the will of the American people. This coward should do the right thing and resign.”