Kevin K. McAleenan, the commissioner of United States Customs and Border Protection, will become the acting secretary of the Department of Homeland Security, President Trump said in a tweet on Sunday.

The announcement came shortly after Mr. Trump said Kirstjen Nielsen was leaving the position, ending a tumultuous tenure in charge of the agency, which oversees border security, among other duties. She had taken the job in late 2017.

Mr. McAleenan, 47, will oversee an agency that has at times been a target of the president’s dissatisfaction over an increase of migrants illegally entering the United States at the southwestern border.

“I have confidence that Kevin will do a great job!” Mr. Trump said in his tweet.

In her resignation letter, Ms. Nielsen said she hoped the incoming secretary would “have the support of Congress and the courts in fixing the laws which have impeded our ability to fully secure America’s borders and which have contributed to discord in our nation’s discourse.”