WASHINGTON — The White House has found a way to bypass a federal statute that dictates who can fill secretary positions, potentially allowing President Trump to choose whomever he wants to lead the Department of Homeland Security, according to an administration official. The route may run through an office established to counter weapons of mass destruction.

The Trump administration has encountered legal and personnel challenges in its search for a candidate who is aligned enough with Mr. Trump to carry out his hard-line immigration agenda and satisfy the legal credentials to be the acting secretary of a department riddled with vacancies.

After Kevin K. McAleenan, the acting secretary who had a tumultuous relationship with the White House, announced this month that he would resign, it was widely believed in the administration that Mr. Trump would tap someone who would not question his more extreme policies. Mr. McAleenan has said he will step down on Thursday.

But officials leading agencies in homeland security who echo Mr. Trump’s fiery language on immigration were initially deemed ineligible under the federal Vacancies Act. The law states that acting officials who take over cabinet-level positions must be next in the line of succession, have the approval of the Senate or have served 90 days under the previous secretary.