A “lonely” Donald Trump has accused James Mattis of being happy to subsidise the armed forced of other countries at the expense of the US – the latest attack on his outgoing defence secretary.

In one of a series of tweets from the White House, where the president is holed up for Christmas as a result of the government shutdown, he hit out at people who had accused him of not attaching importance to relationships with the US’s traditional allies.

“I am all alone (poor me) in the White House waiting for the Democrats to come back and make a deal on desperately needed border security,” the president wrote, three days into a shutdown triggered by his refusal to compromise on a funding package that did not include $5bn for a border wall.

He said those who criticised him for failing to protect relationships with Nato countries and others, were wrong.

“What I don’t like, however, is when many of these same countries take advantage of their friendship with the United States, both in military protection and trade,” he wrote.

“We are substantially subsidising the militaries of many VERY rich countries all over the world, while at the same time these countries take total advantage of the US, and our TAXPAYERS, on trade. General Mattis did not see this as a problem. I DO, and it is being fixed.”

Hours after the tweets, the first lady, Melania Trump was seen boarding a flight back to DC from Florida. The Daily Mail said the first lady, wearing a red coat, appeared to be travelling by herself, as the couple's son, 12-year-old Barron, was not seen. Previously it had been reported that both were returning to Washington.

Mr Trump’s comments followed the resignation last week of the former Marine Corps general who announced he was quitting with a scalding critique of the president and his worldview. In letter that more than one commentator described as a rebuke of Trumpism, Mr Mattis said he believed the president deserved a defence secretary who shared more of Mr Trump’s views.

“We must do everything we can to advance an international order that is most conducive to our security, prosperity and values and we are strengthened in this effort by solidarity of our alliances,” Mr Mattis wrote.

Support free-thinking journalism and attend Independent events

“Because you have the right to have a secretary of defence whose views are better aligned with yours on these and other subjects, I believe it is right for me to step down from my position.”

He added: “One core belief I have always held is that our strength as a nation is inextricably linked to the strength of our unique and comprehensive system of alliances and partnerships. While the US remains the indispensable nation in the free world, we cannot protect our interests or serve that role effectively without maintaining strong alliances and showing respect to those allies.”

The president has repeatedly accused many Nato members of failing to pay two per cent of their GDP on their militaries – something each member is committed to doing. In 2017, only five countries met that requirement – the US (3.6 per cent), the UK (2.1 per cent), Poland (2.0 per cent), Greece (2.4 per cent) and Estonia (2.1 per cent).

Mr Trump has said the US has to pick up the bill for those nations that fail to meet their commitment, especially Germany, the largest economy in Europe. At a meeting of Nato nations in July, he accused Germany of being “a captive” of Russia because it bought natural gas from Moscow.

Who could be running against Trump in 2020? Show all 23 1 /23 Who could be running against Trump in 2020? Who could be running against Trump in 2020? Joe Biden The former vice president - poised to be a frontrunner - has announced his run. He recently faced scrutiny for inappropriate touching of women, but was thought to deal with the criticism well AFP/Getty Who could be running against Trump in 2020? Bernie Sanders The 2016 runner-up has announced that he will be running again in 2020 Getty Who could be running against Trump in 2020? Hillary Clinton The 2016 Democratic presidential candidate and former Secretary of State says she is “still considering” whether she will run again. Getty Who could be running against Trump in 2020? Pete Buttigieg The Indiana mayor and war veteran will be running for president. If elected, he would be the first openly LGBT+ president in American history. Getty Who could be running against Trump in 2020? Kamala Harris The former California attorney general will be running for president in 2020. Introduced to the national stage during Jeff Sessions’ testimony, she has endorsed Medicare-for-all and proposed a major tax-credit for the middle class. AP Who could be running against Trump in 2020? Elizabeth Warren The Massachusetts Senator has formally launched her bid for president in 2020. A progressive Democrat, she is a major supporter of regulating Wall Street. AP Who could be running against Trump in 2020? Beto O’Rourke The former Texas congressman told Oprah Winfrey that he “has been thinking about running for presidency”, but stopped short of formally announcing his bid to run in 2020. AFP/Getty Who could be running against Trump in 2020? Wayne Messam Mayor of the city of Miramar in the Miami metropolitan area, Wayne Messam has announced his bid. He intends to run on a progressive platform against the "broken" federal government. He favours gun regulations and was a signatory to a letter from some 400 mayors condemning President Trump's withdrawal from the Paris Climate Accord. Vice News Who could be running against Trump in 2020? Kirsten Gillibrand The New York Senator formally announced her presidential bid in January, saying that “healthcare should be a right, not a privilege.” Getty Who could be running against Trump in 2020? Cory Booker The New Jersey Senator has announced that he will be running for the presidency in 2020. If he secures the nomination he said finding a female vice president would be a priority. Getty Who could be running against Trump in 2020? John Delaney The Maryland congressman was the first to launch his bid for presidency, making the announcement in 2017. AP Who could be running against Trump in 2020? Julian Castro The former San Antonio mayor announced his candidacy in January and said that his running has a “special meaning” for the Latino community in the US. Getty Who could be running against Trump in 2020? Tulsi Gabbard The Hawaii congresswoman announced her candidacy in January, but is likely to face tough questions on her past comments on LGBT+ rights and her stance on Syrian President Bashar al-Assad. Getty Who could be running against Trump in 2020? Andrew Yang The entrepreneur has announced his presidential candidacy, and has pledged that he would introduce a universal basic income of $1,000 a month to every American over the age of 18. AFP/Getty Who could be running against Trump in 2020? Marianne Williamson The author and spiritual advisor has announced her intention to run for president. She had previously run for congress as an independent in 2014 but was unsuccessful. Getty Who could be running against Trump in 2020? John Kerry The former secretary of state has said he is still thinking about whether to run. Getty Who could be running against Trump in 2020? Michael Bloomberg The entrepreneur and former New York mayor– with a net worth of around $50bn – has said he will decide by the end of February whether to seek the presidency. AFP Who could be running against Trump in 2020? Howard Schultz Former Starbucks CEO Howard Schultz has not yet ruled out running for president in 2020, despite criticism that his bid could help re-elect Mr Trump by dividing the Democrat vote. AP Who could be running against Trump in 2020? Eric Holder The former attorney general has said he will decide in “the next month or so” whether to run as a 2020 presidential candidate. AP Who could be running against Trump in 2020? Eric Swalwell The California congressman said he is “ready to do this” and will decide before April whether to run. MSNBC Who could be running against Trump in 2020? Terry McAuliffe The former Virginia governor, who worked to elect Democratic governors during 2018 midterms, said there was a “50 per cent” chance he would run. AP Who could be running against Trump in 2020? Sherrod Brown The Ohio senator is still undecided about whether to run for president in 2020. Who could be running against Trump in 2020? Mitch Landrieu The former New Orleans mayor said he doesn’t think he will run for president, but “never say never”. AP Photo/Jacquelyn Martin

He also said other leaders had agreed to spend more on their militaries at his instigation.

“I told people that I would be very unhappy if they didn’t up their commitments very substantially, because the United States has been paying a tremendous amount,” the president said.

“Now people are going to start — and countries are going to start upping their commitments. And now we’re very happy and have a very, very powerful, very, very strong Nato — much stronger than it was two days ago.”

While Mr Trump has claimed the US is “paying the bills” of other countries, experts say that is not strictly true.

“There is no ledger that maintains accounts of what countries pay and owe,” former Obama administration national security council staff member Aaron O’Connell told NPR, this summer. “Nato is not like a club with annual membership fees.”