WASHINGTON — President Trump on Monday ordered an across-the-board employment freeze for the federal government, halting hiring for all new and existing positions except those in national security, public safety and the military.

In the two-page order, Mr. Trump said the directive was a stopgap way to control the growth of government until his budget director recommends a long-term plan to significantly reduce the federal work force through attrition.

“In carrying out this memorandum, I ask that you seek efficient use of existing personnel and funds to improve public services and the delivery of these services,” Mr. Trump wrote in the memorandum, one of his first acts as president. “Accordingly, this memorandum does not prohibit making reallocations to meet the highest priority needs and to ensure that essential services are not interrupted and national security is not affected.”

The largest public employees union blasted the president’s action, saying it will force federal agencies to rely on more expensive contractors to deliver the services that Americans have come to expect from the government.