Homeland Security Secretary Kirstjen Nielsen's tough stance at the U.S.-Mexico border in recent weeks may have saved her job, according to reports.

Nielsen’s post-midterm job performance, particularly her tough response to the migrant caravan, seems to have impressed President Trump, who previously said she wasn't a strong enough defender of the border, Politico reported.

Support from administration allies such as Defense Secretary James Mattis and Secretary of State Mike Pompeo has also helped Nielsen's cause -- as have Nielsen's own words and actions at the border, the report said.

“No one has been working harder to implement the president’s security-focused agenda than Secretary Nielsen,” DHS spokesman Tyler Houlton told Politico. “She is fully focused on supporting the men and women of DHS, the mission at hand, and solving the crisis at the border.”

US HARDENS BORDER AT TIJUANA TO PREPARE FOR MIGRANT CARAVAN

In November, Nielsen defended the use of tear gas against migrants entering the U.S., echoing Trump's argument.

“They had to use [it] because they were being rushed by some very tough people. And they used tear gas. Here’s the bottom line: Nobody’s coming into our country unless they come in legally,” Trump told reporters in November, according to the Washington Post.

Nielsen suggested that border agents used tear gas after migrants threw "rocks and projectiles" at them, according to another report by the Post. Authorities were entitled to "self-defense," she added.

In October, Nielsen sat down for an interview on Fox News' "The Story with Martha MacCullum" to discuss the migrant caravan's imminent arrival at the U.S.-Mexico border, which Trump had sharply focused on heading into the November midterms.

Trump had firmly stated that migrants would not be allowed to enter the country illegally, and hundreds of U.S. troops were set to make their way to the southern border to help Homeland Security and National Guard troops deal with the caravan.

Nielsen echoed the president's words with a warning for any migrants who illegally crossed the U.S. border.

"You will be returned home," she said.

"If they come here illegally with no legitimate reason to stay, they absolutely will be apprehended and removed immediately," Nielsen said, adding that "everything is on the table" for how to deal with the caravan.

"This caravan cannot come to the United States. They will not be allowed in. They will not be allowed to stay," she told MacCallum.

Meanwhile, White House Chief of Staff John Kelly, a longtime Nielsen supporter, has spent months lobbying to save her job, Politico reported. And Nielsen's strong relationships with Pompeo and Mattis also have helped, the report said.