WASHINGTON — President Donald Trump unloaded on Homeland Security Secretary Kirstjen Nielsen at a heated cabinet meeting this week, railing against her for failing to stop illegal border crossings.

Trump, who has growing increasingly frustrated by a spike in apprehensions at the border and other legal setbacks, blamed Nielsen Wednesday for failing to do enough to stop them, according to people familiar with the exchange.

Nielsen, one person said, tried to explain the issues were complex and that the department’s powers were limited by a slew of legal restrictions. She told the president her team was doing everything it could, but the president was left unconvinced.

The episode, first reported by The New York Times, left Nielsen on the verge of resignation, according to the paper, which also said Nielsen, the former deputy White House chief of staff, had drafted — but not submitted — a resignation letter.

But the department pushed back on that characterization.

Homeland Security spokesman Tyler Houlton said in a tweet that, “The @nytimes article alleging that the Secretary drafted a resignation letter yesterday and was close to resigning is false.”

The @nytimes article alleging that the Secretary drafted a resignation letter yesterday and was close to resigning is false. The Secretary is hard at work today on the President's security-focused agenda and supporting the men and women of @DHSgov. — Tyler Q. Houlton (@SpoxDHS) May 10, 2018

The secretary, he added, was “hard at work” Thursday “on the President’s security-focused agenda and supporting the men and women of @DHSgov.”

Nielsen did not deny the meeting had grown heated in a statement Thursday evening, but said she shared the president’s frustrations.

“The President is rightly frustrated that existing loopholes and the lack of Congressional action have prevented this administration from fully securing the border and protecting the American people. I share his frustration,” she said in a statement.

She added that, “Border security is the most basic and necessary responsibility of a sovereign nation” and said she would “continue to direct the Department to do all we can to implement the President’s security-focused agenda.”

Trump has growing increasingly angry about his inability to secure the border and has repeatedly called on Congress to pass new legislation to strengthen what he calls the nation’s “horrible” immigration laws.

Trump has also been frustrated with Nielsen, who previously served as Chief of Staff John Kelly’s deputy, according to people familiar with the dynamic, who spoke on condition of anonymity because they were not authorized to disclose private conversations.

During a rally in Elkhart, Indiana Thursday evening, Trump complained that, “We have the worst immigration laws in the history of mankind” and urged voters to “give me some reinforcements, please” in the form of new Republican members.

While border apprehensions dipped last year to their lowest levels ever, the numbers have been ticking up in recent months, returning to more typical historical levels.

Trump has also been frustrated with Congress’s refusal to fully fund his promised border wall along the nation’s southern border, and some in the administration had accused DHS leaders of slow-walking more aggressive efforts to separate children from their parents at the border.

U.S. Attorney General Jeff Sessions this week announced a new “zero-tolerance” policy toward people who enter the United States illegally that may cause more separations. A conviction for illegal entry carries a maximum penalty of six months in custody for first-time crossers, though they usually do far less time, and two years for repeat offenses.

Associated Press writer Ken Thomas contributed to this report.

READ MORE: Seeking asylum in the U.S. under Trump