President Trump said late Friday that he is replacing Kevin McAleenan, the acting homeland security secretary, after a tenure in which McAleenan reduced border crossings and shepherded major Trump administration immigration policies but clashed with other senior officials and struggled to earn the president’s trust.

“Kevin McAleenan has done an outstanding job as Acting Secretary of Homeland Security. We have worked well together with Border Crossings being way down. Kevin now, after many years in Government, wants to spend more time with his family and go to the private sector,” Trump said of his top immigration official in a tweet.

McAleenan had become increasingly frustrated with a cadre of Trump’s appointments to senior immigration roles, and he recently told The Washington Post that he was struggling to control the messaging coming out of his department. More hard-line figures have attacked him as insufficiently committed to the president’s immigration agenda, while critics of the administration’s policies argue McAleenan has used conciliatory rhetoric to lend cover to harsh measures.

Trump, in turn, had questioned whether McAleenan was loyal to him.

A person close to McAleenan, who spoke on the condition of anonymity, said he resigned Friday after weeks of growing disenchantment with his standing in the administration. He was never formally nominated for the job and there was no indication he would be.

Kevin McAleenan, the acting homeland security secretary, acknowledged May 22 during a House hearing the deteriorating conditions at migrant detention centers. (Reuters)

McAleenan, who focused his tenure on addressing what he has characterized as an immigration system at the breaking point, recounted his accomplishments in a statement Friday night. He also thanked the president for the opportunity to serve “alongside the men and women of the Department of Homeland Security.”

“With his support, over the last 6 months, we have made tremendous progress mitigating the border security and humanitarian crisis we faced this year, by reducing unlawful crossings, partnering with governments in the region to counter human smugglers and address the causes of migration, and deploy additional border security resources,” McAleenan said in the statement.

In an interview with The Post last week, McAleenan said that while he had maintained operational control of his department and its agencies, he felt he had lost the ability to shape how the Trump administration characterized immigration enforcement.

A career law enforcement official, McAleenan had tried to present a relatively neutral approach to the border and felt that political partisanship was taking over.

“What I don’t have control over is the tone, the message, the public face and approach of the department in an increasingly polarized time,” McAleenan said in the interview. “That’s uncomfortable, as the accountable, senior figure.”

Ken Cuccinelli, acting director of U.S. Citizenship and Immigration Services, is viewed as a potential replacement for McAleenan.

The former Virginia attorney general has distinguished himself in the role by making frequent television appearances during which he often weighs in on the affairs of other DHS agencies, appearing at times as a more eager spokesman for the president’s immigration policies than McAleenan.

But acrimony between Cuccinelli and leading GOP senators would be a major obstacle to his confirmation, and the administration would have to perform a series of bureaucratic maneuvers to go outside the order of succession to leapfrog him into the acting secretary role.

Trump’s pick to replace McAleenan will be the fifth DHS chief in less than three years, an unprecedented level of turmoil at the top of a department that was created to project stability and to safeguard the nation through careful coordination across the government.

Under Trump, the position has morphed into a border cop role. One administration official remarked recently that former homeland security secretary Kirstjen Nielsen — who McAleenan replaced — spent 80 percent of her time on immigration, but McAleenan spends 99 percent of his time on the issue.

McAleenan’s tenure at DHS was marked by the implementation of several contentious border policies that have significantly tightened access to the U.S. asylum system — policies he has defended as necessary to “restore integrity” to a U.S. immigration system swamped with a backlog of nearly 1 million pending cases. He was vocal in declaring that the U.S. immigration system was at a breaking point earlier this year as a crush of Central American migrant families streamed to the border seeking asylum, and he has advocated for agreements with other countries that would shift the burden of accepting asylees away from the United States.

McAleenan has been more isolated in recent weeks after the departure of several top aides and close allies. In addition, his relationships have been strained with other senior figures, especially Mark Morgan, the acting commissioner of Customs and Border Protection, and Cuccinelli.

The acting secretary’s exit leaves the bare-bones leadership structure at DHS even thinner. Every major immigration agency is run by leaders in acting roles.

DHS was created after the 9/11 terrorist attacks, and previous presidents have placed a high priority on having a Senate-confirmed leader running the department, which has 240,000 employees and a $50 billion annual budget.

Trump, who has said he prefers leaving top officials in “acting” roles to make it easier to remove them, left McAleenan in the job without a nomination for six months, longer than any other previous DHS chief.

The department’s acting deputy secretary, David Pekoske, is next in line to succeed McAleenan. Pekoske, who also is the top official at the Transportation Security Administration, is the one of the few senior DHS leaders who have been confirmed by the Senate.

Unlike McAleenan, Pekoske does not have a background in immigration enforcement, and he has told others he would like to return to his job running TSA full time.

McAleenan’s departure opens the possibility the president will seek to install a more hard-line figure at the top of DHS for the duration of his reelection campaign. In his tweet Friday, Trump said he would name a new acting secretary next week.

Trump installed McAleenan, 48, at the head of the department after ousting Nielsen, saying he wanted someone “tougher” in the role. Trump told aides that McAleenan had the look he was going for, with the trim, stern demeanor of a federal agent.

Trump was willing to look past the warnings of border hawks who told him McAleenan was an “Obama guy” raised in California who had a record of donating to Democrats.

Trump said in June that he was preparing to place former Immigration and Customs Enforcement director Tom Homan in the role of a White House “border czar.” Homan did not accept the position, but several administration officials have speculated that the president will establish such a role at the White House to coordinate among federal agencies responsible for immigration and border enforcement.

Asked last month why Trump had not nominated McAleenan for the DHS job despite praising his performance, White House officials declined to comment.

“Secretary McAleenan is doing a fantastic job implementing the president’s plan to secure the southern border, build the wall, halt illegal immigration and stop the dangerous practice of catch-and-release,” Hogan Gidley, the deputy White House press secretary, said in a statement to The Washington Post at the time.

McAleenan’s exit ends a nearly 20-year career in federal law enforcement. He was recruited to join CBP after 9/11, creating and running the agency’s anti-terrorism office. At 35, he was port director in charge of security for Los Angeles International Airport and 17 other airports in southern California.

He was confirmed as CBP commissioner in March 2018 in a 77-to-19 vote, a margin that reflected his standing among Democrats as a moderate and a career official.