The UK government has defended a deal to give the Chagos Islands to Mauritius and lease back a key military base, following criticism from US President Donald Trump over its handling.

In a post on social media, Trump labelled the move as an act of great stupidity, months after he and senior US officials endorsed it. Later on Tuesday he confirmed he was against the deal.

The UK government said it would never compromise on our national security, while the prime minister's official spokesperson insisted the US still supported the move.

The UK signed the £3.4bn ($4.6bn) agreement in May, under which it would retain control of a UK-US military base on the largest of the islands, Diego Garcia.

In a post on his Truth Social platform that morning, Trump had said: Shockingly, our 'brilliant' NATO Ally, the United Kingdom, is currently planning to give away the Island of Diego Garcia, the site of a vital U.S. Military Base, to Mauritius, and to do so FOR NO REASON WHATSOEVER.

“There is no doubt that China and Russia have noticed this act of total weakness.

Responding, the prime minister's official spokesman said that the US supports the deal and the president explicitly recognised its strength last year. He added that it was also backed by the UK's Five Eyes allies, the other members of which - besides the UK and US - are Canada, Australia, and New Zealand.

Earlier, a UK government spokesperson said it had acted because the base on Diego Garcia was under threat after court decisions undermined our position and would have prevented it operating as intended in future. They added that the agreement had secured the operations of the joint US-UK military base for generations, with robust provisions for keeping its unique capabilities intact and our adversaries out, and noted the deal had been welcomed by allies including the US.

The Chagos Islands are a reasonably important area of the globe, Trump stated, indicating he believes they should remain under UK control.

However, Mauritius' attorney general Gavin Glover expressed confidence that the agreement would proceed, highlighting that it was negotiated, concluded and signed exclusively between the United Kingdom and the Republic of Mauritius.

The Chagos Islands, part of a long-standing sovereignty dispute, were separated from Mauritius in 1965. Under the current deal, the UK retains control of Diego Garcia while transferring sovereignty of the islands to Mauritius. This strategic move is viewed as essential for the continued operation of US and UK military interests in the region.