Her position had been weakened by the departure of John Kelly, as chief of staff, who had been one of her strongest allies.
Ms Nielsen had not only aroused the ire of Mr Trump, but also Stephen Miller, the president’s hard-line immigration adviser.
They felt that she had failed to protect the US border and held her responsible for the sharp increase in migrants trying to enter the country from Latin America.
Ms Nielsen will be replaced, for the time being, by Kevin McAleenan, the commissioner of Customs and Border Protection.
Her departure is a further reflection of the revolving door in Mr Trump’s administration which has seen at least 40 high-profile departures since he took, office.
Departures include a raft of cabinet members including Rex Tillerson, the Secretary of State, Ryan Zinke, the Interior Secretary and Health and Human Services Secretary, Tom Price and James Mattis, the Defence Secretary.