Ruling in the court of appeal backs Guardian campaign to have letters to ministers released under freedom of information law

Three senior judges have ruled that Dominic Grieve, the attorney general, acted unlawfully when he blocked the publication of letters written by Prince Charles to government ministers.

The ruling, led by Lord Dyson, the head of the civil judiciary in England and Wales, paves the way for the release of the letters, which reveal how the prince lobbied government ministers to change official policies.

Grieve had refused access to the letters, arguing that they could cause constitutional problems. He had said their contents could seriously damage the prince's ability to perform his duties when he became king because they could cast doubt on his political neutrality.

On Wednesday Dyson and two colleagues in the appeal court quashed a veto that Grieve had used to override an independent tribunal. The freedom of information tribunal had previously ruled against the government and had ordered that the letters should be disclosed because the public had a right to see how the heir to the throne had sought to influence government.

Under freedom of information legislation, the Guardian has for nine years sought to view the letters that Grieve says contain the prince's "most deeply held personal views and beliefs".

On Wednesday Dyson said the attorney general had been given permission to seek to appeal against the ruling at the supreme court. He also ordered the attorney general to pay the Guardian's legal costs, amounting to £96,000.

Dyson, the master of the rolls, said Grieve did not have reasonable grounds for issuing the veto "merely because he disagrees with the decision" of the tribunal.

Grieve "could point to no error of law or fact in the [tribunal's] decision, and the government departments concerned did not even seek permission to appeal it", he added.

A month after the tribunal's decision in 2012, Grieve, with the support of the cabinet, had used the veto because he said the public could interpret the letters sent to ministers in the last Labour government as showing Charles to be "disagreeing with government policy".

Grieve had said that a cornerstone of the British constitution was that the monarch could not be seen to be favouring one political party over another. But he had said that any perception that Charles had disagreed with Tony Blair's government "would be seriously damaging to his role as future monarch because, if he forfeits his position of political neutrality as heir to the throne, he cannot easily recover it when he is king".

The 27 pieces of correspondence between Charles and ministers in seven government departments between September 2004 and April 2005 "are in many cases particularly frank", according to Grieve.

In Wednesday's court of appeal judgment Dyson, along with Lord Justices Richards and Pitchford, said Grieve "had no good reason for overriding the meticulous decision" of the tribunal, which examined evidence from constitutional experts and arguments from barristers for the government and the Guardian.

Dyson called the verdict from the tribunal – which was chaired by a high court judge – "an impressive piece of work". Dyson also ruled that the veto was unlawful under European commission law.

The prince has for many years been criticised for apparently exploiting his unelected position to promote his views and persuade ministers to change official policies through private letters, nicknamed "black-spider memos" because of his scrawled handwriting.

The freedom of information tribunal heard that he had been writing to ministers as long ago as 1969, when he expressed concern to the then prime minister, Harold Wilson, about the fate of Atlantic salmon.

The tribunal, in its decision in September 2012, had come out in favour of publishing the letters, saying: "The essential reason is that it will generally be in the overall public interest for there to be transparency as to how and when Prince Charles seeks to influence government."

The letters concerned involve ministers in the Cabinet Office and the departments responsible for business, health, schools, environment, culture and Northern Ireland.

The government has argued that even the dates on which the letters were sent, and on which ministers received them, should be kept secret.

The government has also delayed disclosing the amount of money it has spent on barristers and lawyers to resist the disclosure of the letters in court hearings and the freedom of information tribunal. That piece of information has also been requested by the Guardian.

A Guardian News and Media spokesperson said: "The public has a right to know if the heir to the throne is advocating policy or promoting causes to government ministers.

"We welcome today's appeal court judgment finding that it was wrong to block the release of the letters. We hope the attorney general will recognise he has reached the end of the legal road and that government departments will now publish the correspondence so that the public can judge for themselves."

A spokesman for the attorney general said: "We are very disappointed by the decision of the court. We will be pursuing an appeal to the supreme court in order to protect the important principles which are at stake in this case."