Christopher Miller, the current head of the National Counterterrorism Center, will take on the role immediately.
It follows a public falling-out between Mr Trump and Mr Esper in recent weeks.
Mr Trump has so far not conceded the US election to President-elect Joe Biden, and has vowed to challenge the projected result in court.
In the weeks before Mr Biden takes office on 20 January, Mr Trump is still empowered to make decisions.
Mr Miller was seen entering the Department of Defense headquarters at the Pentagon on Monday shortly after Mr Trump announced the dismissal.
The former Special Forces soldier served on President Trump’s National Security Council before becoming head of the Counterterrorism Centre in August.
In a resignation letter, Mr Esper thanked members of the Armed Forces and said he was proud of his achievements in 18 months of service at the Pentagon.
“I serve my country in deference to the Constitution, so I accept your decision to replace me,” he wrote.
Top Democrat Nancy Pelosi criticised the decision. “The abrupt firing of Secretary Esper is disturbing evidence that President Trump is intent on using his final days in office to sow chaos in our American Democracy and around the world,” said the speaker of the House of Representatives.
Mr Esper clashed with the president over the White House’s attitude to the military during protests over racial injustice earlier this year.
As protests rocked the US following the death of black man George Floyd at the hands of police in Minneapolis, Minnesota, in May, Mr Trump threatened to use troops to suppress unrest.
In June, Mr Esper, a former army officer, said the use of active-duty forces was unnecessary, in remarks that were known to have displeased the White House.
Following the clash, it was widely-speculated that the president would fire the defence secretary, although on Monday Mr Trump gave no reason for his dismissal.
Mr Esper has also disagreed with Mr Trump over the president’s dismissive attitude towards Nato.
In an interview with Military Times last week, Mr Esper said that despite the difficult relationship with the White House, he didn’t believe quitting was the right thing to do.
“The president’s going to — he’s very transparent in terms of what he wants. And he’s been very clear about his views … I’m not trying to make anybody happy,” he told the website.
“What I’m trying to do is, fulfil what he wants — I mean, he’s the duly elected commander in chief — and make the best out of it.”
President Trump has fired a significant number of his officials and advisers during his tenure, often using Twitter to announce the dismissal.
Mr Esper’s predecessor was James Mattis, who resigned in 2018 over differences with the president including about the war in Syria.
In June, as racial injustice protests were ongoing, Mr Mattis criticised Donald Trump as the “first president in my lifetime who does not try to unite the American people – does not even pretend to try. Instead he tries to divide us.”
Source: News Agencies and BBC