In their 126-page ruling, the judges, led by Mr Justice Walker, acknowledged that some people "fear, among other things, that disclosure would damage our constitutional structures". However, they dismissed the arguments put forward by the Whitehall departments, saying they had a "strong air of unreality" and were "difficult to pin down".

The departments had argued that the correspondence between the prince and ministers had to be kept secret under a constitutional convention. Disclosure would undermine the convention which allowed the heir to the throne to be educated in the business of government to prepare him to become king, they claimed.

But the judges decided that permitting the prince's lobbying to be concealed under this convention was a "massive extension" of the convention, which was not justified. They decided that "it was fundamental" that the lobbying by the heir "cannot have constitutional status" and cannot be protected from disclosure.

The evidence, they said, "shows Prince Charles using his access to government ministers, and no doubt considering himself entitled to use that access, in order to set up and drive forward charities and promote views, but not as part of his preparation for kingship".

"Ministers responded, and no doubt felt themselves obliged to respond, but again not as part of Prince Charles's preparation for kingship."

The judges noted that although the public had strong views about Charles, they had made their decision "dispassionately – in the words of the judicial oath, 'without fear or favour, affection or ill-will'".

They said: "Some will be horrified at any suggestion that correspondence between government and their heir to the throne should be published … Others may welcome such disclosure, fearing among other things that without it there will be no real ability to understand the role played by Prince Charles in government decision-making."

The judges noted that the prince's activities "are not neutral and in a number of respects have been controversial".

Adam Tomkins, a law professor, had testified that the prince had lobbied on "the perceived merits of holistic medicine, the perceived evils of genetically modified crops, the apparent dangers of making cuts in the armed forces, his strong dislike of certain forms of architecture (leading him to make high-profile interventions in a number of contested planning developments), a range of issues relating to agricultural policy".

According to media reports, the prince once complained to Tony Blair, when he was prime minister, about the government's treatment of rural workers, relaying a Cumbrian farmer's view that "if we, as a group, were black or gay, we would not be victimised or picked on".

On another occasion he outlined his concerns to Lord Irvine, then lord chancellor, about an American-style "compensation culture", reportedly writing: "I and countless others dread the very real and growing prospect of an American-style personal injury 'culture' becoming ever more prevalent in this country".

He was also reported to have criticised "the degree to which our lives are becoming ruled by a truly absurd degree of politically correct interference".

Copies or details of the prince's letters have been made public, either through leaks, Jonathan Dimbleby's 1994 biography of Charles, or other sources. However, the tribunal's decision is the first time under the freedom of information legislation that the government has been instructed to publish his letters.

It is likely to be the last time, as ministers last year enforced a blanket ban on his correspondence being disclosed under the freedom of information law in the future, regardless of whether it is in the public interest. The absolute block was imposed following pressure from the royal family, a well-placed source has told the Guardian.

The judges ordered the Cabinet Office, and the departments responsible for business, health, schools, environment, culture and Northern Ireland to disclose their correspondence with the prince between September 2004 and April 2005.

It is the second freedom of information defeat the government has suffered over the question of the prince's political influence. The Queen and the prince have the power to veto legislation that could harm their private interests. Last month the information commissioner ruled that an internal Whitehall guide into the use of this veto should be published.