Image copyright AFP/Getty Image caption The prince wrote to seven government departments

The attorney general's refusal to let the public see letters the Prince of Wales wrote to UK ministers has been ruled unlawful by the Court of Appeal.

Guardian journalist Rob Evans had challenged Dominic Grieve's decision to veto a High Court tribunal ruling in favour of allowing their publication.

Mr Grieve argued that releasing the letters would undermine the principle of the heir being politically neutral.

He was granted permission to appeal the latest ruling to the Supreme Court.

In September 2012 the Upper Tribunal, headed by a High Court judge, ruled that Mr Evans and the public were entitled to see the letters under the Freedom of Information Act 2000 (FOIA) and under the Environmental Information Regulations 2004.

Media playback is unsupported on your device Media caption Guardian editor Alan Rusbridger says his newspaper is trying to clarify the role of the monarchy, rather than damage them

The seven government departments concerned did not appeal the decision but a month later the attorney general intervened and imposed a veto under section 53 of the FOIA.

Mr Grieve had said the departments were legally entitled to refuse disclosure because the correspondence was part of the prince's "preparation for becoming king".

But on Wednesday, the Court of Appeal ruled that the certificate should be quashed because Mr Grieve had "no good reason" for overriding the decision of the tribunal and he had acted in a way which was incompatible with European law.

Lord Dyson, Master of the Rolls, said the fact that Mr Grieve reached a different conclusion to the Upper Tribunal (UT) was not enough.

"He had no good reason for overriding the meticulous decision of the UT reached after six days of hearing and argument.

Image copyright PA Image caption Dominic Grieve said he would appeal the Court of Appeal's verdict

"He could point to no error of law or fact in the UT's decision and the government departments concerned did not even seek permission to appeal it."

Responding to the verdict, a spokesman for Mr Grieve 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."

Dominic Grieve's argument is that it is better to pretend Charles is impartial than to prove he is not Graham Smith, Republic

The "advocacy correspondence" was described as letters the prince had written in 2004 and 2005 seeking to advance the work of charities or to promote views.

Guardian editor Alan Rusbridger told BBC Radio 4 the prince was a "powerful person" who should be "above politics".

He went on: "If that's wrong then we should have a transparent and open debate about it.

"But if the Prince of Wales is going to try and influence public policy in a particularly frank way then I don't think he is acting as a private citizen and therefore like any other lobby group there ought to be transparency about what he's trying to do."

Republic, which campaigns for the abolition of the monarchy, welcomed the decision.

"Dominic Grieve's argument is that it is better to pretend Charles is impartial than to prove he is not," spokesman Graham Smith said.

In 2010, the Freedom of Information Act was tightened up and now royal letters cannot be made public for 20 years or five years after the writer's death, whichever is longer.

Mr Smith said that law change gave the Royal Family "complete freedom to lobby the government in secret and on whatever issue they choose", adding: "This has nothing to do with their royal duties and everything to do with the Windsor family protecting their own interests and pursuing their own agendas."