The UK should end its control of the Chagos Islands in the Indian Ocean "as rapidly as possible", the UN's highest court has said.
Mauritius claims it was forced to give up the islands — now a British overseas territory — in 1965 in exchange for independence, which it gained in 1968.
The International Court of Justice said the islands were not lawfully separated from the former colony of Mauritius.
The UK Foreign Office said: "This is an advisory opinion, not a judgment."
It added it would look "carefully" at the detail of the opinion, which is not legally binding.
The UK has previously said it will hand the islands back to Mauritius when they are no longer required for defence purposes.
Referencing that, the Foreign Office said: "The defence facilities on the British Indian Ocean Territory help to protect people here in Britain and around the world from terrorist threats, organised crime and piracy."
Judge Abdulqawi Ahmed Yusuf described the UK's administration of the Chagos Islands — located more than 2,000 miles off the east coast of Africa — as "an unlawful act of continuing character".
He added the UK was "under an obligation to bring an end to its administration of the Chagos Archipelago as rapidly as possible".
The UN General Assembly asked the court in February 2017 to offer its opinion in on whether the process had been concluded lawfully.
It is half a century since the UK took control of the Chagos Islands from its then colony, Mauritius.
The British government evicted the entire population, before inviting the US to build a military base on Diego Garcia, one of the larger atolls.
Mauritius was in the middle of negotiating its independence from the UK at the time and has repeatedly condemned the deal.
Some of those who were forced to leave their homes on the Chagos Islands in the late 1960s hoped they would be allowed to return — and not just on one of the rare visits authorised by the UK.
Speaking to the BBC last year, Samynaden Rosemond, who left when he was 36, said: "Back home was paradise."
He and his wife, Daryela, moved to the outskirts of the capital of Mauritius, Port Louis.
Chagossians often complain that they are treated as second-class citizens in Mauritius, and they often gather to cook coconut and fish curry and to sing songs about the life they left behind.
Mr Rosemond added: "The British didn't give us a chance. They just said: 'Oh, this is not yours anymore.'
"If I die here my spirit will be everywhere — it wouldn't be happy. But if I die there I will be in peace."