Top Democratic lawmakers, national security experts and other analysts ripped President Trump on Wednesday after he mocked his own top intelligence officials for contradicting his foreign policy opinions — telling them they “should go back to school.”

“The President has a dangerous habit of undermining the intelligence community to fit his alternate reality. People risk their lives for the intelligence he just tosses aside on Twitter,” tweeted Virginia Sen. Mark Warner, the ranking Democrat on the Senate Intelligence Committee.

“It is a credit to our intelligence agencies that they continue to provide rigorous and realistic analyses of the threats we face. It’s deeply dangerous that the White House isn’t listening,” added Rep. Adam Schiff, chair of the House Intelligence Committee.

House Majority Leader Steny Hoyer called Trump’s denial dangerous.

“On almost every national security challenge the president is in denial or has a different view than the intelligence community. That’s unfortunate. It’s not good for the country and it’s not good for our allies because they don’t think they can rely on us, which is dangerous for them and dangerous for us,” Hoyer told Hill TV.

A few Republicans also piled on, including Senate Majority Whip John Thune.

“I don’t know how many times you can say this but I prefer the president would stay off Twitter- particularly with regard to these important national security issues,” he told CNN.

Ex-CIA director John Brennan, a frequent Trump critic, echoed Hoyer’s charge.

“Your refusal to accept the unanimous assessment of U.S. Intelligence on Iran, No. Korea, ISIS, Russia, & so much more shows the extent of your intellectual bankruptcy. All Americans, especially members of Congress, need to understand the danger you pose to our national security,” he wrote on Twitter.

University of Connecticut historian Bradley Simpson called Trump’s attacks on his own top intel officials unprecedented.

“As a historian of US foreign relations, I can honestly say that [there] has never been anything like this before: a President openly expressing not just disagreement, but contempt for his own intelligence community because they will not parrot his lies. Just astonishing,” he tweeted.

University of Alabama law professor and former federal prosecutor Joyce White Vance wrote on Twitter that even the president’s most hard-core fans might doubt his version of reality following the Senate testimony from Director of National Security Dan Coats, who appeared along with CIA chief Gina Haspel, FBI Director Christopher Wray and other top officials.

“Do even the most hardcore Trump supporters believe he is smarter than the 17 agencies that make up the US intelligence community? I think they must all privately have doubts. As they should,” she wrote.

Veteran diplomat Richard Haas, president of the Council on Foreign Relations, called it “remarkable” that Trump would ignore his own intel chiefs.

“There is nothing remarkable about the view that NK will keep its nuclear weapons, that Iran complying with the JCPOA, that ISIS not defeated. What is remarkable is that the Potus and his administration do not share these views and are not acting on them,” he tweeted.

Coats said Tuesday that ISIS has not been defeated, Iran is not producing nukes and North Korea is unlikely to abandon its own nuclear weapons program.

All of those positions were at odds with the president’s proclamations that ISIS had been defeated, Iran remained a nuclear threat and that North Korea was on its way to denuclearization.

Coats also emphasized that Russia and China — countries whose leaders the president has repeatedly praised — remained the biggest threats to US security.

He did not mention what Trump calls the “crisis” at the Mexican border.

On Wednesday morning, Trump fired back in a pair of tweets.

“The Intelligence people seem to be extremely passive and naive when it comes to the dangers of Iran. They are wrong! When I became President Iran was making trouble all over the Middle East, and beyond. Since ending the terrible Iran Nuclear Deal, they are MUCH different, but a source of potential danger and conflict,” the commander in chief wrote.

“They are testing Rockets (last week) and more, and are coming very close to the edge. There [sic] economy is now crashing, which is the only thing holding them back,” he continued. “Be careful of Iran. Perhaps Intelligence should go back to school!”