President Donald Trump told acting Homeland Security Secretary Kevin McAleenan last week to close the southern border and that he would pardon him if he faced any legal challenges, according to The New York Times.

The paper, citing three people briefed about the conversation, reported that they spoke when Trump visited the border town of Calexico, California, last week shortly before he named McAleenan acting homeland security secretary.

One of the officials briefed on the conversation said they did not know whether the president was joking. But Trump's remarks alarmed officials at the agency who were briefed on it, The Times said.

NBC News has not independently confirmed the report.

Tyler Houlton, a spokesman for DHS, denied Trump had asked McAleenan to do anything illegal.

"At no time has the president indicated, asked, directed or pressured the acting secretary to do anything illegal," Houlton said. "Nor would the acting secretary take actions that are not in accordance with our responsibility to enforce the law."

Earlier this month, Trump said he was "100 percent" prepared to shut down the U.S. border with Mexico to block an influx of migrants. However, he later backtracked saying that he would give Mexico one year to stop the flow of illegal drugs entering the U.S. before imposing tariffs or closing the southern border.

However, the Times reported that Trump was privately pushing his aides to stop the influx of migrants across the southern border.

The news comes after the head of DHS, Kirstjen Nielsen, resigned under pressure on Sunday night. NBC News previously reported that Nielsen had refused to reinstate the administration's controversial child separation policy — putting her at odds with the president.