President Trump last week privately urged Kevin McAleenan, the border enforcement official he was about to name as acting secretary of homeland security, to close the southwestern border to migrants despite having just said publicly that he was delaying a decision on the step for a year, according to three people briefed about the conversation.

It was not clear what Mr. Trump meant by his request or his additional comment to Mr. McAleenan that he would pardon him if he encountered any legal problems as a result of taking the action. Federal judges have already blocked the administration’s attempts to limit asylum seekers who illegally enter the country, and it is not likely that Mr. McAleenan would have ended up in jail if he had followed the president’s directive.

One of the people briefed on the conversation said it was possible Mr. Trump had intended the comments to Mr. McAleenan as a joke. But the conversation, which took place during the president’s visit to the border town of Calexico, Calif., alarmed officials at the Department of Homeland Security who were told of it, according to the people familiar with the remarks.

It was another instance of the president trying to undo a decision and to stretch the boundaries of his power, even when told there were legal issues at stake. The same situation played out on Friday, when Mr. Trump said he was considering releasing asylum seekers into so-called sanctuary cities after administration officials told reporters the proposal was rejected because of legal issues.