WASHINGTON — The White House on Monday warned State Department officials that they should leave their jobs if they did not agree with President Trump’s agenda, an extraordinary effort to stamp out a wave of internal dissent against Mr. Trump’s temporary ban on entry visas for people from seven predominantly Muslim countries.

Career officials at the State Department are circulating a so-called dissent cable, which says that Mr. Trump’s executive order closing the nation’s doors to more than 200 million people with the intention of weeding out a handful of would-be terrorists will not make the nation safer, and might instead deepen the threat.

“These career bureaucrats have a problem with it?” Sean Spicer, the White House press secretary, told reporters. “They should either get with the program or they can go.”

It was yet another stark confrontation between the new president, who is moving swiftly to upend years of policies, and a federal bureaucracy still struggling with the jolting change of power in Washington. There is open hostility to Mr. Trump’s ideas in some pockets of the government, and deep frustration among those enforcing the visa ban that the White House announced the order without warning or consulting them.