Chagos islanders evicted by the British government in the 1970s today lost their long-running battle to return to the Indian Ocean archipelago.

The islanders had previously won the right to return to all islands except Diego Garcia, the main island, where there is a US military base.

The 3-2 ruling today by the law lords overturns the islanders' victory and is the final stage of a legal battle that started 10 years ago.

Lord Hoffmann ruled the government was entitled to legislate for a colony in the security interests of the United Kingdom.

The US state department had argued that the islands might be useful to terrorists.

Lord Hoffmann said: "Some of these scenarios might be regarded as fanciful speculations, but in the current state of uncertainty the government is entitled to take the concerns of its ally into account."

He rejected the argument by the Chagossians' lawyers that the government did not have the power to remove their right of abode in what is now known as the British Indian Ocean Territory (BIOT). "The law gives it and the law may take it away," he said.

Lord Rodger and Lord Carswell agreed. Lord Bingham and Lord Mance dissented.

Olivier Bancoult, the evicted islander who put his name to the legal bid when it started in 1998, said after the ruling: "We are deeply disappointed but of course we fight on. We are consulting our legal team to see what we can do."

Bancoult urged ministers to read the statements of the dissenting judges. "They should put an end to the shameless victimisation of Chagossians and adopt a lawful policy of facilitating our return to our homeland."

Britain took the Chagos islands from France in the Napoleonic wars. In 1971 the British government used an immigration ordinance to remove the inhabitants compulsorily so Diego Garcia could be used as a US base.

Both the divisional court and the court of appeal had previously ruled that the Chagossians could return to the outer islands. The Foreign Office appealed against those judgments to the law lords.

The foreign secretary, David Miliband, welcomed today's judgment as a vindication of the government's decision to appeal.

"We do not seek to excuse the conduct of an earlier generation. Our appeal to the House of Lords was not about what happened in the 1960s and 1970s. It was about decisions taken in the international context of 2004.

"This required us to take into account issues of defence [and] security of the archipelago and the fact that an independent study had come down heavily against the feasibility of lasting resettlement of the outer islands of BIOT."

In his dissenting judgment, Lord Bingham declared as void and unlawful a 2004 order to declare, without the authority of parliament, that no person had the right of abode in the Chagos islands.

The power to legislate without going to parliament was "an anachronistic survival", he said. "The duty of protection cannot ordinarily be discharged by removing and excluding the citizen from his homeland."

Lord Mance said factors relied on as justifying the order were based on a "remote and unlikely risk" of large-scale resettlement of the outer Chagos islands.

Richard Gifford, who represented the Chagossians, said: "It has been the misfortune of the Chagos islanders that their passionate desire to return to their homeland has been caught up in the power politics of foreign policy for the past 40 years.

"Sadly, their struggle to regain their paradise lost has been dismissed on legal grounds, but the political possibilities remain open for parliament the British public and the international community to continue to support."

The law lords were told during the hearing in July that Diego Garcia was regarded by the US since the 9/11 terrorist attacks as a "defence facility of the highest importance ... a linchpin for the UK's allies".

The Foreign Office argued that allowing the Chagossians to return would be a "precarious and costly" operation, and the United States had said that it would also present an unacceptable risk to its base.

While there were "undeniably unattractive aspects" to what had happened to the islanders in the 1970s, that was no longer what the case was about, Jonathan Crow QC, for the foreign secretary, told the lords. "The Chagossians do not own any territory," Crow said. "They have no property rights on the islands at all. What is being asserted is a right of mass trespass."

Ten years ago the Chagossians began legal action for the right to return, and in 2000 the divisional court ruled their eviction illegal . The foreign secretary at the time, Robin Cook, agreed they should be allowed to return to all the islands except Diego Garcia. But after the September 11 attacks in 2001, the US said Diego Garcia had become an important base for the wars in Afghanistan and Iraq.

In 2004, the UK government issued orders in council that negated the court's ruling, but two years later the high court ruled in favour of the Chagossians. In May last year the government lost again at appeal. In November the lords granted the government leave to appeal but ordered it to pay all legal costs, regardless of the decision.

A recent study found the small number of islanders likely to want to return to the archipelago permanently would be able to make a sustainable living.

The study, backed by the Let Them Return campaign and written by John Howell, a former director of the Overseas Development Institute, suggested there were "no physical, economic or environmental reasons" to prevent resettlement on the islands of Peros Banhos and Salomon.

Howell suggested about 150 families - fewer than 1,000 people and about a quarter of those entitled to go back - would want to return. Eco-tourism and fish exports could provide jobs and income. The total cost to the UK of resettlement would be about £25m, the report said.