The Government's immigration policy was in tatters yesterday after a judge ruled that treatment of skilled workers who had challenged retrospective tightening of the rules was unfair and unlawful.

The Home Secretary was ordered to pay costs and refused the right to appeal.

The decision undermines controversial changes made retrospectively to test criteria for the government's Highly Skilled Migrants Programme (HSMP).

The Home Office said analysis showed that the previous test was "not sufficiently rigorous to select those migrants who were making the greatest economic contribution to the UK."

But the changes were attacked in the High Court by campaign group HSMP Forum as unlawful and a breach of migrants' legitimate expectations.

Yesterday they won an important legal victory when judge Sir George Newman allowed their challenge and granted them judicial review.

The decision was welcomed by the Scottish Government, which is seeking to use the Fresh Talent scheme to boost the economy by bringing in more skilled migrants.

A spokeswoman said last night: "While we won't comment on individual cases, the Scottish Government welcomes the enormous contribution that migrants make to our culture and our economy.

"We would hope that that is reflected in the consideration of cases and in the development of the new immigration system.

"This issue reinforces the argument for Scotland to have more responsibility for immigration matters."

Critics claimed that up to 90% of the 49,000 migrants who came to work in the UK under the scheme faced being forced to leave because they would have to reapply under the new points-based system.

They argued many would no longer qualify for permanent residency and faced the prospect of deportation with their families, despite having made their home in the UK.

The government disputed the claim and said the numbers affected were "very small".

The judge said individuals had made statements about the hardships they would face and asked: "If the new changes are likely to affect so few a number of people, what interest is there to be served by subjecting a limited number of people to considerable hardship which they would not otherwise have faced?"

He said the changes were "unfair" to those already admitted to the UK under the programme.

He added that there was "no good reason why those already on the scheme shall not enjoy the benefits of it as originally offered to them."

Jacqui Smith, the Home Secretary, was ordered to pay the Forum's legal costs and refused permission to appeal, but she can still ask the Court of Appeal to hear the case.

Liam Byrne, the Border and Immigration minister, said: "This is a very straightforward case which affects just 1300 highly skilled migrants.

"Did we give migrants a big enough warning that the rules could get tougher while they were here? We said yes, others said no.

"That's why it was right for a judge to take a look at this case, and I will now decide whether to appeal against his ruling."

In his ruling the judge said it was unnecessary for him to determine whether the government had failed to comply with its duty under the 1971 Race Relations Act, but there was an admission that "shortcomings" had been disclosed.

David Davis, the shadow Home Secretary, said: "As well as voting against the changes, we warned the government repeatedly that retrospective changes to HSMP were both unfair and potentially illegal.

"It is unfair that skilled workers who have made a commitment to this country should have the rules of the game changed."