Media playback is unsupported on your device Media caption Lord Justice Gross expressed "grave concern" over secret trial

An unprecedented attempt to hold the first ever completely secret criminal trial in the UK has been blocked by the Court of Appeal.

Judges said that the "core" of the terrorism trial could be partly heard in secret but parts must be in public.

They said media also should be allowed to name the two defendants as Erol Incedal and Mounir Rarmoul-Bouhadjar.

Prosecutors said their unique application for a secret trial was in the interests of national security.

They had previously warned that they may have to abandon the prosecution if judges did not ban the press and the public from every part of the proceedings against the two defendants.

Until Thursday, the men were previously only known as AB and CD respectively.

In their decision, judges said that the trial of the two men was of an exceptional nature and the core of it must be held in private. But they added that they had "grave concerns" about the cumulative effect of anonymising defendants and holding the hearings in secret.

Image copyright other We express grave concern as to the cumulative effects of holding a criminal trial in camera and anonymising the defendants. We find it difficult to conceive of a situation where both departures from open justice will be justified. Lord Justice Gross

The judges said that the media and public would be allowed to attend the swearing-in of the jury, parts of the prosecution's introductory remarks setting out the case, the verdicts and, where there are convictions, the sentencing.

The court added that a small number of journalists could be allowed to attend the closed parts of the trial, subject to agreement relating to the confidentiality of the proceedings. Their notes would be securely stored until the end of the trial.

Mr Incedal and Mr Rarmoul-Bouhadjar were arrested in October 2013 in circumstances that were widely reported at the time. Mr Incedal is charged with preparing for acts of terrorism contrary to the Terrorism Act 2006 and a further allegation of collecting information useful to terrorism.

Mr Rarmoul-Bouhadjar is charged with collecting information useful to terrorism and possession of false identity documents.

Lord Justice Gross said: "Open justice is both a fundamental principle of the common law and a means of ensuring public confidence in our legal system.

"Exceptions are rare and must be justified on the facts. Any such exceptions must be necessary and proportionate. No more than the minimum departure from open justice will be countenanced."

He said that those exceptions could include withholding information on the basis of national security because that was "a national interest of the first importance".

"For the [secret intelligence] agencies to operate effectively, at least much of their work is secret and must remain so as a matter of necessity. From time to time, tensions between the principle of open justice and the needs of national security will be inevitable.

What can and can't be reported

Swearing in of the jury and reading the charges

Part of the judge's introductory remarks

Part of the prosecution opening speech

Verdicts and sentencing, if there are convictions

No reporting of "core of the trial"

Court may approve small number of journalists to witness in-camera hearings, but their notes will be kept at the end of each day

Court may review need for continued secrecy at the end of the trial

'Administration of justice'

The judge said that the court accepted the exceptional nature of the case against the two defendants and that there was a significant risk or "at the very least a serious possibility" that the Crown would have good reasons to halt the prosecution were the case to be heard in open court.

"In our judgment, as a matter of necessity, the core of the trial must be heard in camera [behind closed doors]."

"We are not persuaded, on the material before us, that there is a risk to the administration of justice warranting anonymisation of the defendants," he continued. "Nor do we think that, properly understood, the Crown's material supported that outcome, provided the bulk of the trial was in camera.

"We add only this. We express grave concern as to the cumulative effects of holding a criminal trial in camera and anonymising the defendants. We find it difficult to conceive of a situation where both departures from open justice will be justified. Suffice to say, we are not persuaded of any such justification in the present case."

A spokesman for the attorney general said the Crown Prosecution Service would abide by the court's decision.

"The measures applied for by the CPS in this case were, they believed, justified in order for the trial to proceed and for the defendants to hear the evidence against them while protecting national security," said the spokesman.

"We are pleased that the court recognised the strength of some of these arguments, and that the case can go ahead. The CPS has indicated it accepts the judgment of the court and will tailor its approach to the prosecution accordingly."

Isabella Sankey, director of policy for campaign group Liberty, said the judges' verdict was better than a "blacked-out trial", but criticised the court's "deference" to ministers' national security concerns.

She added: "Shutting the door on the core of a criminal trial is a dangerous departure from our democratic tradition."

But Lord Carlile, a former independent reviewer of terrorism legislation for the government, said it was "absolute nonsense" to suggest the justice system was under threat.

He said: "Most right-thinking members of the public would agree that if national security, particularly people's safety, is affected, then there may well have to be some parts of a trial held in secret."