Departing Sen. Jeff Flake on Wednesday ripped President Trump for attacking the media as the “enemy of the people,” comparing his remarks to Soviet dictator Josef Stalin and calling them a “source of great shame.”

“It is a testament to the condition of our democracy that our own president uses words infamously spoken by Josef Stalin to describe his enemies​,” the Arizona Republican said on the Senate floor.

“It bears noting that so fraught with malice was the phrase ​’enemy of the people’​ that even Nikita Khrushchev forbade its use, telling the Soviet Communist Party that the phrase had been introduced by Stalin for the purpose of ​’​annihilating such individuals​’​ who disagreed with the supreme leader​,” Flake continued.

​He said Trump’s “repulsive” statements ​show he has it backward — “despotism is the enemy of the people.”

“This alone should be a source of great shame for us in this body, especially for those of us in the president’s party,” he said. “The free press is the despot’s enemy, which makes the free press the guardian of democracy. When a figure in power reflexively calls any press that doesn’t suit him ‘fake news,’ it is that person who should be the figure of suspicion, not the press.”

Flake, a vocal critic of the president who is not seeking re-election, blasted Trump’s use of the term “fake news” and ticked off a number of falsehoods put forward by the president during the 2016 campaign and his first year in the White House.

He recalled Trump referring to the Russia probe as a “hoax,” alleging massive voter fraud during the election and spreading the conspiracy theory that former President Barack Obama wasn’t born in the US.

He urged his Democratic and Republican colleagues in Congress “to be allies in the truth and not partners in its destruction.”

“Here in America, we do not pay obeisance to the powerful. In fact, we question the powerful most ardently. To do so is our birthright​,​”​ he said.

Flake also rebuked Trump for saying he would announce fake news media awards.

“It beggars belief that an American president would engage in such a spectacle. But here we are,” he said.

Not only do the president’s assaults on a free press have a “destructive effect” on our democracy, they also embolden foreign leaders to subvert the media to remain in power, he said.

Listing Syrian strongman Bashar al-Assad calling an Amnesty International report “fake news,” Philippines President Rodrigo Duterte blaming “fake news” for demonizing him and Singapore promising to enact “fake news” legislation, Flake said the “feedback loop is disgraceful.”

“Not only has the past year seen an American president borrow despotic language to refer to the free press, but it seems he has in turn inspired dictators and authoritarians with his own language. This is reprehensible,” he said.