OSLO (Reuters) - Norway's supreme court ruled on Friday it was legal to expel two nine-year-old asylum seekers, even though they had spent most or all of their lives in the country, in a case lawyers said could set a precedent for another 540 children.

The court rejected an appeal launched on the children's behalf by a campaign organization that had argued the Bosnian girl and the Iranian boy had a right to remain after their parents' asylum application was turned down.

"The 540 children seeking asylum in Norway have no chance now, regardless how long they waited," Jan Fougner, a defense lawyer for one of the families said.

The ruling meant Mahdi Shabazi, who came to Norway at the age of two, would almost certainly be deported, said lawyers.

Verona Delic, who was born in the Nordic nation, had already been deported to Bosnia with her family and would now have to stay, they added.

Norwegian laws require courts to review asylum cases for children separately if their parents' application is rejected but authorities rarely make a different ruling in their cases.

It was the first time the issue had been taken to Norway's top court.

Norway has welcomed workers from the EU but it takes a tougher stance on other immigrants, particularly asylum seekers.

"The primary tool for helping people in need for Norway is to provide foreign aid where people live since it is beyond the capability of the Norwegian state to help all in need," said Judge Arnfinn Baardsen.

Opponents of wider immigration say they are trying to stop human trafficking and people coming to the country to enjoy its generous welfare system.

(Reporting by Vegard Botterli; Writing Balazs Koranyi; Editing by Andrew Heavens)