U.S. Homeland Security Secretary Kirstjen Nielsen answers questions during the daily briefing at the White House in Washington, D.C., U.S., June 18, 2018.

Kirstjen Nielsen is leaving her role as Homeland Security secretary as President Donald Trump intensifies his focus on the nation's border with Mexico.

Trump said on Sunday that she is leaving her position and thanked Nielsen for her service. Kevin McAleenan, the current Customs and Border Protection commissioner, will serve as acting Homeland Security secretary.

Although she was originally set to vacate the position immediately, Nielsen later said in a Twitter post that she had agree to stay on through Wednesday, April 10 "to assist with an orderly transition and ensure that key DHS missions are not impacted."

Trump has sought to toughen his policy on the southern border in recent weeks. The president threatened to shut large portions of the border if Mexico did not stem the flow of migrants and drugs.

He later backed down from that threat, giving Mexico a year to meet his demands or face car tariffs or a border closure.

Trump tweet 2

A White House aide told CNBC that Nieslen's departure was unexpected despite months of speculation about whether she would be fired or quit.

In her resignation letter, Nielsen said she had "determined that it is the right time for me to step aside" without out citing reasons why.

Nieslen Tweet: Its been an honor of a lifetime to serve with the brave men and women of @DHSgov. I could not be prouder of and more humbled by their service, dedication, and commitment to keep our country safe from all threats and hazards.

Nielsen was a protege of former White House chief of staff John Kelly, who stepped down in frustration over his inability to bring discipline to Trump's chaotic administration. Kelly had led Homeland Security before he took over the chief of staff position in summer 2017.

She had reportedly considered resigning last year after Trump criticized her in front of the Cabinet, accusing her of failing to secure the country's borders.

Nielsen also faced heated criticism from Democrats for defending the administration's policy of separating migrant families who arrive at the border. Democrats had called for her resignation last year.

The Washington Post reports that several names have been floated to replace Nielsen, including Energy Secretary Rick Perry, who was also reportedly considered for the role when Kelly left the position.

"Secretary Perry is very happy where is, leading the Department of Energy," a Department of Energy spokesperson told CNBC.

The White House is also considering former Virginia Attorney General Ken Cuccinelli, former Kansas Secretary of State Kris Kobach and former Florida Attorney General Pam Bondi to head up Homeland Security, according to the Post.

CNBC's Tom DiChristopher contributed to this article.