Mr. Mattis, according to administration officials familiar with the deliberations, was not consulted by the White House during the preparation of the order and was not given an opportunity to provide input while the order was being drafted. Last summer, Mr. Mattis sharply criticized Mr. Trump’s proposed ban on Muslim immigration as a move that was “causing us great damage right now, and it’s sending shock waves through the international system.”

Customs and Border Protection officers were also caught unaware.

They contacted several airlines late Friday that were likely to be carrying passengers from the seven countries and “instructed the airlines to offload any passport holders from those countries,” said a state government official who has been briefed on the agency’s actions.

It was not until 3 a.m. on Saturday that customs and border officials received limited written instructions about what to do at airports and border crossings. They also struggled with how to exercise the waiver authority that was included in the executive order, which allowed the homeland security secretary to let some individuals under the ban enter the country case by case.

One customs officer, who declined to be quoted by name, said he was given a limited briefing about what to do as he went to his post on Saturday morning, but even managers seemed unclear. People at the agency were blindsided, he said, and are still trying to figure things out, even as people are being stopped from coming into the United States.

“If the secretary doesn’t know anything, how could we possibly know anything at this level?” the officer said, referring to Mr. Kelly.

At the Citizenship and Immigration Service, staff members were told that the agency should stop work on any application filed by a person from any of the countries listed in the ban. Employees were told that applicants should be interviewed, but that their cases for citizenship, green cards or other immigration documents should be put on pause, pending further guidance.