Britain paid the then self-governing colony of Mauritius £3 million ($5.7m) for the islands in 1965. It combined them with three islands from the Seychelles to create British Indian Ocean Territory.
Three islands were subsequently returned to the Seychelles. But Britain retained the Chagos Archipelago, which had been chosen as the site of a major base for the US navy and air force.
The International Court of Justice found that although Mauritius' Government agreed to the division when it gained independence in 1968, the "detachment was not based on the free and genuine expression of the will of the people concerned".
The court said: "The United Kingdom is under an obligation to bring to an end to its administration of the Chagos Archipelago as rapidly as possible, allowing Mauritius to complete the decolonisation of its territory."
Pravind Jugnauth, the Prime Minister of Mauritius, hailed the ruling as a "historic moment". He added: "Our territorial integrity will now be made complete, and when that occurs, the Chagossians and their descendants will finally be able to return home."
Britain has apologised for the "shameful" way the evictions were carried out but has refused to allow Chagossians to return.
Diego Garcia was an important US base during the Iraq and Afghanistan conflicts, acting as a launch pad for long-range bombers. The US lease lasts until 2036. The US joined Britain in voting against the resolution.