The American president took to Twitter to announce his replacement as well.
Mr Esper clashed with the president over the White House's use of the military to quell public unrest during protests over racial injustice earlier this year.
Esper's firing has raised concerns that other top national security officials who have earned Trump's wrath may be next in the line of fire.
CNN reported that Esper was expecting to resign regardless of the election outcome, claiming that his relationship with Trump had significantly deteriorated.
The US president also said that Christopher C. Miller has been appointed as acting defence secretary in Esper's place. Trump nominated him for the post of director of the National Counterterrorism Centre in May 2020 and Miller was successfully vetted by the Congress in August, replacing acting Director Lora Shiao.
Greta Thunberg mocks Trump by recycling his tweet
In a clip that subsequently went viral, Thunberg could be seen glaring at the US President as he made his way through the event. The message was actually written by Donald Trump a year ago and was written about Greta Thunberg .
Mr. Trump has steadfastly refused to acknowledge his election loss.
"Mark Esper has been terminated", tweeted Trump, talking about the defense secretary with whom he openly disagreed on how to tackle civil unrest in the United States five months ago.
In recent months he was subjected to White House ire over his insistence that the Pentagon and USA military not be part of the President's reelection campaign, in contrast to the actions of Attorney General William Barr, Director of National Intelligence John Ratcliffe, Secretary of State Mike Pompeo, and Agriculture Secretary Sonny Purdue.
Representative Adam Smith, the Democrat who leads the House Armed Services Committee, condemned Trump's decision as "childish" and "reckless".
Esper's predecessor, Jim Mattis, quit in 2018 over policy differences with Trump, including on Syria. "We are not in one of those situations now", Esper had said.
Mattis was Trump's first defense secretary and a popular figure among the troops. "Mark "Yesper"? Did you call him 'Yesper?'" Trump said, in what appeared to be an allusion to suggestions that Esper was a yes man for the president.