WASHINGTON — President Trump lashed out at the nation’s intelligence agencies on Wednesday, accusing them of being “passive and naive” about the dangers posed by Iran, and defending his handling of Afghanistan, North Korea and the Islamic State.

A day after the agencies issued their annual assessment of global threats — warning of malefactors like China and the Islamic State — Mr. Trump reignited a long-simmering feud with his own government, reacting as if the report was a threat to him personally.

“Perhaps Intelligence should go back to school!” he declared on Twitter in an indignant early morning post. In another, Mr. Trump said, “The Intelligence people seem to be extremely passive and naive when it comes to the dangers of Iran. They are wrong!”

Normally, the “Worldwide Threat Assessment” is an annual bureaucratic exercise, a dispassionate survey of the threats facing the United States — some longstanding, some new — that the White House accepts without much comment.

Mr. Trump, however, treated the report, presented at a Senate Intelligence Committee hearing on Tuesday by Dan Coats, the director of National Intelligence; Gina Haspel, the C.I.A. director; and other officials appointed by the president, as a scorecard on his foreign policy, and something close to an affront.

His outburst laid bare the rift between the bureaucracy and a president who came into office determined to challenge decades of foreign policy orthodoxy. It also revealed Mr. Trump’s deep frustration at what he believes is the lack of credit he has received for his efforts, be it his diplomacy with North Korea’s leader, Kim Jong-un, or his more confrontational policy toward Iran.

It thrust the spy agencies into an extremely awkward position, putting them at odds with the commander in chief and sowing doubts among Mr. Trump’s supporters about whether the agencies can be trusted — the kind of public battering that has tarnished the credibility of the F.B.I.

Above all, it revealed the president’s tendency to view everything through the prism of his own achievements.

To be sure, the agencies did contradict Mr. Trump’s assessment of two of the major threats: North Korea, they said, was unlikely to give up its nuclear arsenal, even after Mr. Trump’s diplomacy with Mr. Kim. Iran, which Mr. Trump has painted as an implacable enemy, is not taking steps to manufacture a nuclear bomb, they said.

Mr. Trump’s dismissal of the threat report led some critics to ask where the president gets his foreign policy advice.

The answer, say people who have worked with him, is a flickering parade of talking heads on Fox — hard-line foreign policy experts, retired generals and longtime on-air personalities — who praise his actions, savage his critics and validate his “America First” approach to the world.

Members of this circle rotate in and out of the White House. John R. Bolton, a longtime Fox commentator who served in the George W. Bush administration, is now Mr. Trump’s national security adviser, and has been influential in hardening his strategy toward Iran.

Sebastian Gorka, a little-known academic who made his name in conservative circles with his writings about Islamic radicalism, left a job at the White House after he could not obtain a security clearance, and now stoutly defends the president’s policies on Fox.

Lou Dobbs, a longtime anchor for Fox Business Network, has helped shape Mr. Trump’s view on China and trade over decades. Michael Pillsbury, the hawkish China scholar has become influential since Mr. Trump became president.

That is not to say that these outsiders invariably back Mr. Trump. Mr. Keane, one of the most prominent outside voices, went on Fox to condemn Mr. Trump’s abrupt decision in December to pull troops out of Syria as a “huge strategic mistake,” which he would “come to regret.”

The president later agreed to a more gradual drawdown — a reversal that Mr. Keane’s criticism may have helped bring about, according to people who know Mr. Trump, since his set the tone for an almost unanimously negative reaction on the part of Republicans.