Guardian journalist Rob Evans accused Dominic Grieve, the Government’s principal legal adviser, of failing to show “reasonable grounds” for blocking disclosure.
The Upper Tribunal, headed by a High Court judge, declared in September 2012 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.
The Government departments concerned with the correspondence did not appeal, but a month later the Attorney General issued a certificate under section 53 of the FOIA and used his ministerial veto.
Today Lord Dyson, the Master of the Rolls, and two other judges, Lord Justice Richards and Lord Justice Pitchford, ruled that the certificate should be quashed because Mr Grieve had “no good reason” for overriding the decision of the Upper Tribunal and he had acted in a way which was incompatible with European law.
The Attorney General was granted permission to appeal against today’s ruling to the Supreme Court, the highest court in the land. The quashing order is stayed pending his appeal.
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.”
Mr Grieve said, in his opinion, Government departments were legally entitled to refuse disclosure because the correspondence was undertaken as part of the Prince’s “preparation for becoming king”.
Making the letters public could potentially damage the principle of the heir to the throne being politically neutral, and so undermine his ability to fulfil his duties when king, said Mr Grieve.
Dinah Rose QC argued on behalf of Mr Evans and the Guardian at the appeal hearing last month that Mr Grieve had used Section 53 “executive override” powers merely because he disagreed with the Upper Tribunal. “The implications for the rule of law are grave,” she said.
Lawyers for Mr Grieve told the court that Parliament clearly intended allowing the Attorney General “to have the power to take his own view of what was in the public interest” despite the view reached by the tribunal.
But today Lord Dyson ruled: “The Attorney General did not have reasonable grounds for forming the opinion on which the (Section 53) certificate was based.
“The mere fact that he reached a different conclusion from the Upper Tribunal (UT) in weighing the competing public interests involved was not good enough.
“He had no good reason for overriding the meticulous decision the UT reached after six days of hearing and argument.
“He could point to no error or fact in the UT’s decision and the Goverrnment departments concerned did not even seek permission to appeal it.
“The certificate is also unlawful because it is incompatible with EU law.”
Both of the other judges agreed.
Mr Evans wants to shed more light “on the way the heir to the throne seeks to influence government ministers even though he holds no elected position”.
He applied to see a number of written communications between Charles and various Government ministers between September 2004 and April 2005.
The Information Commissioner upheld the refusal of disclosure, but Mr Evans won his appeal to the Upper Tribunal.
The tribunal judges ruled that Mr Evans was entitled to “advocacy correspondence” from Charles, described as letters he had written seeking to advance the work of charities or to promote views.
But the Attorney General disagreed, and last July three High Court judges - led by the then lord chief justice Lord Judge - upheld his decision.
They ruled the use of the veto was lawful, and that Mr Grieve had reasonable grounds for deciding it was “an exceptional case meriting use of the ministerial veto to prevent disclosure and to safeguard the public interest”.
Today the three appeal judges disagreed with the three High Court judges and ruled they had got the law wrong and their decision must be set aside.
It will now be for yet another panel of judges, this time at the Supreme Court, to make a final ruling.
The seven Government departments Charles wrote to are Business, Innovation and Skills; Health; Children, Schools and Families; Environment, Food and Rural Affairs; Culture, Media and Sport; the Northern Ireland Office and the Cabinet Office.
The case is believed to mark the first time that anyone has challenged the Attorney General’s powers to block access to information.
A Guardian News & Media spokeswoman 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.”
Lord Dyson said of the UT ruling in favour of disclosure: “On any view, the decision is a most impressive piece of work.”
The UT decided that Mr Evans was entitled to see “advocacy correspondence”, in which the prince advocated certain causes which were of particular interest to him.
It was common ground “that significant parts of the correspondence consisted of environmental information”, said the judge.
The Attorney General had disagreed with the decision of the UT, an independent court chaired by a High Court judge “on the very question which the UT had examined in meticulous detail”, even though he did not have any additional material, said the judge.
It was not suggested that the UT had made any error of law or fact, and it was accepted that its decision was a reasonable decision.
Lord Dyson ruled: “I do not consider that it is reasonable for an accountable person (the Attorney General) to issue a section 53(2) certificate merely because he disagrees with the decision of the tribunal. Something more is required.
“Examples of what would suffice are that there has been a material change of circumstances since the tribunal decision or that the decision of the tribunal was demonstrably flawed in fact or in law.”