This article is more than
5 year oldCustoms and Border Protection Commissioner Kevin McAleenan will replace her temporarily, Mr Trump said.
Ms Nielsen was responsible for the proposed border wall with Mexico and the separation of migrant families.
Her resignation came after the president indicated he wanted to follow a "tougher" immigration policy.
He has often accused Ms Nielsen of not being tough enough.
In recent months, illegal crossings from Central America have surged and Mr Trump has threatened to close the Mexico border.
He has since backtracked and promised to give Mexico a year to stop drugs and migrants crossing into the US.
The New York Times reported that Ms Nielsen went into a meeting with Mr Trump on Sunday to plan "a way forward" with the border situation.
Instead, she was put under pressure to resign from her job, US media say, citing unnamed sources.
She gave no reason for her departure in her resignation letter, although she said this was "the right time for me to step aside" and said the US "is safer today than when I joined the Administration".
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. pic.twitter.com/lIQ5iqGDmF
— Sec. Kirstjen Nielsen (@SecNielsen) April 7, 2019
Ms Nielsen first joined Mr Trump's administration in January 2017 as an assistant to the former Homeland Security chief John Kelly.
She became Mr Kelly's deputy when he moved to become White House chief of staff, but returned to lead her former department later that year.
Ms Nielsen defended border policies such as holding children in wire enclosures in the face of strong condemnation and intense questioning by Democrats in Congress.
In June 2018 protesters booed Ms Nielsen as she ate at a Mexican restaurant in Washington DC.
But she brushed off the demonstration, tweeting that she would "work tirelessly" to fix the "broken immigration system".
Her relationship with Mr Trump is said to have been difficult, although in public she has been loyal to the administration.
By Anthony Zurcher, BBC senior North America reporter
Kirstjen Nielsen reportedly had been on thin ice in the Trump administration for more than a year. Her closest ally, former Chief of Staff John Kelly, exited the White House in December. Now, along the annual spring thaw, the ice beneath her has finally cracked.
Or perhaps the homeland security secretary simply reached her limit. The real story will have to wait for the inevitable leaks and insider accounts that spread every time this president makes a staffing change.
What seems clear, however, is that there are conflicts taking place behind the scenes in the White House - conflicts accompanying the president's increasingly belligerent rhetoric on immigration.
Just two days ago, Mr Trump rescinded his nomination of Ronald Vitiello to head Immigration and Customs Enforcement because, he said, he wanted to go in a "tougher direction".
Now his homeland security secretary - whom he had in the past viewed as not aggressive enough - is out.
Ms Nielsen's name will forever be associated with the Trump administration's family separation border policy that led to massive bipartisan outcry last year. The president eventually backed down from that fight, but these latest moves suggest a more confrontational approach to border security is all but assured.
Members of the Democratic party have already commented on her departure.
Bennie Thompson, Mississippi congressman and Chair of the Committee on Homeland Security, said Ms Nielsen's tenure was "a disaster from the start", while Massachusetts Senator Ed Markey calling the move "long overdue".
However, he said the fight is "far from over to ensure Trump's assault on our immigrant community comes to an end".
Kirstjen Nielsen may not have been the architect of Donald Trump’s inhumane immigration agenda, but she was its steward and her departure is long overdue. But our fight is far from over to ensure Trump’s assault on our immigrant community comes to an end. https://t.co/lHfAFiJJ84
— Ed Markey (@SenMarkey) April 7, 2019
But Republican Senator Lindsey Graham praised Ms Nielsen, saying she "did her best to deal with a broken immigration system and broken Congress".
And Texas congressman Michael McCaul said she was "a principled voice" who "wholly understands the threats we face".
President Trump insists the situation on the southern border is a crisis and has declared a national emergency, bypassing Congress to secure funds for his border wall plan.
Democrats have protested against the move, and declared the emergency unconstitutional.
Mr McAleenan, 47, was confirmed as the nation's top border protection officer in 2018 with bipartisan support. He previously served as Customs and Border Protection (CBP)'s deputy commissioner under the Obama administration.
In 2015, Mr McAleenan received the highest civil service award from then-President Barack Obama.
Last year, he faced criticism in the media for carrying out Mr Trump's zero tolerance policy that led to the family separation crisis, but he has maintained his agency's duty is to carry out the laws, not create them.
Mr McAleenan is married to Corina McAleenan, an El Salvadoran immigrant, according to the Times, who worked for several years with the US Secret Service.
He is a graduate of Amherst College - where his honours thesis was on marriage equality, the New York Times reported - and he helped develop antiterrorism border security strategies after the 9/11 attacks.
Mr McAleenan received a law degree from the University of Chicago and worked in California before CBP.
Newer articles
<p>The deployment of Kim Jong-un’s troops has added fuel to the growing fire in recent weeks. Now there are claims Vladimir Putin has put them to use.</p>