“Everyone was treated humanely,” Mr. Kelly, a retired Marine Corps general recently confirmed as homeland security secretary, told lawmakers. “We did have to step back and kind of re-cock in that first 24-hour period because of action by one of the federal courts. That changed things a bit, so we had to kind of step back.”

Mr. Kelly said he also agreed with a Twitter post by Mr. Trump that dangerous people could be getting into the country while a court order has held up the ban. He said it was “entirely possible” and it was likely that law enforcement officials would not know “until the boom.”

Representative Michael McCaul, the chairman of the Homeland Security Committee, said the rollout of the executive order had been problematic. Mr. McCaul, a Texas Republican, said he was concerned about “the lack of coordination, both within the executive branch and also with congressional leaders like myself.”

But he said he applauded Mr. Kelly for “quickly correcting what I consider to be errors by quickly granting the exception and waiver to green-card holders, which went a long way to remedy, I think, this executive order.”

Mr. Kelly said most of the confusion had occurred because of the multiple court rulings issued in response to the order and the many protesters who appeared at airports across the country, not because of the actions of Customs and Border Protection officers.

Representative Bennie G. Thompson of Mississippi, the ranking Democrat on the committee, said he agreed that there had been problems with the rollout of the ban. But he rejected Mr. Kelly’s testimony that the order had not caused chaos at airports as customs officers tried to determine who would be denied entry.

“They were put in an untenable position. Basically, they were flying by the seat of their pants trying to interpret an E.O. that had no directives to go with it,” Mr. Thompson said, referring to the executive order. “You had L.A. doing one thing, Atlanta doing one thing and J.F.K. doing another. So I’m troubled by the comment that he made that there was no chaos.”