Allies of Trump had expressed anger and blasted as "unforgivable" McAleenan's comments last week to the Washington Post, where he publicly spoke of his frustration with the president, acting Customs and Border Protection Commissioner Mark Morgan, and acting US Customs and Immigration Services Director Ken Cuccinelli.
"Kevin now, after many years in government, wants to spend more time with his family and go to the private sector", Trump posted minutes before he was supposed to appear at a campaign rally in Louisiana.
Mr Trump had previously threatened to fire Ms Nielsen, who was viewed as resistant to some of the harshest immigration measures supported by the President and his aides, both around the border and on other matters like protected status for some refugees.More news: Brexit talks enter crucial 'tunnel' phase, but gaps on substance remain
McAleenan told The Associated Press he was leaving on his own terms - a contrast to other top administration officials pushed out during Trump's tenure.
Formerly head of US Customs and Border Protection (CBP), McAleenan stepped into the DHS job in April, after the surprise resignation of Secretary Kirstjen Nielsen.
"With (Trump's) 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.More news: US House Republicans to Seek Sanctions on Turkey Over Kurd Offensive
"He did his best as a professional public servant but those qualities are not prized in this administration", said Bersin, an assistant Homeland Security secretary for global affairs and Customs and Border Protection commissioner under Obama.
His tenure played out against a backdrop of outrage amid reports of children being held in squalid conditions on the U.S. border and images of those who died trying to make the trek from Central America.
Trump in turn had questioned whether McAleenan was loyal to him. "That may be why he's no longer there", he said.More news: Huge Brush Fire Prompts Numerous Freeway and Road Closures