Scotland's agency for wildlife and habitats unlawfully allowed beavers to be killed, a judge has ruled.
NatureScot has been ordered to stop issuing licences to cull the animals without first giving its reasons in writing.
The rewilding charity Trees for Life challenged the beaver-killing policy at the Court of Session, saying too many licences were being issued.
Out of five complaints from Trees for Life, four were rejected by the court.
NatureScot said the decision, "for the most part", vindicated their approach.
The ruling applies to all European protected species in the UK.
In a written judgement, Lady Carmichael said all killings authorised by NatureScot had been unlawful and it must in future fully set out the reasons why it believed beavers should be killed.
"In approaching matters on the basis that it has no duty to give reasons for granting a licence, the first respondent has erred in law," she wrote.
"The contention is that the licences should have been reviewed and revoked because they should never have been issued in the first place."
But Lady Carmichael added that she was "not satisfied" with some of the arguments put forward by Trees for Life about NatureScot's "generalised unlawful practices", adding that some "criticisms are misconceived".
Trees for Life's Alan McDonnell said: "The Scottish government has been blocking relocation of beavers to areas of Scotland where they belong but are missing, but [the] ruling creates hope that this will change so that farmers will no longer be put in a position where they have no choice but to shoot much-loved animals."
Beavers 'can cause problems'
NatureScot director Robbie Kernahan said: "We welcome the court's decision which, for the most part, vindicates our licensing approach.
"We have been successful on all points of law except that we should have issued written reasons with each licence to explain why it had been granted."
He said they had been working to bring beavers back to Scotland for 25 years because of the benefits the animals could bring to people and nature, but "in certain circumstances, beavers can cause problems".
Sarah-Jane Laing, chief executive of Scottish Land and Estates - a membership organisation for landowners, rural businesses and rural professionals - said: "We continue to hold the view that lethal control should only be used as a last resort, and greater resources from government and other organisations will allow intervention to occur earlier where required."