Facebook and Twitter users will face lengthy jail sentences if they defy court orders banning publication of information, one of the country's most senior judges has ruled.

In a judgement that will have major ramifications for policing the internet, Sir John Thomas warned social media users that they were not above laws that govern conventional press.

His comments came after a test case brought by the Attorney General against two men who were part of a “concerted campaign” to publish images purporting to be of James Bulger's killers on the 20th anniversary of the toddler's death.

Dean Liddle and Neil Harkins narrowly escaped nine months in jail when Sir John, president of the Queen's Bench Division, and Mr Justice Tugendhat agreed to suspend the sentences for 15 months.

But Sir John said: “For the future, if there is publication on the internet or through social media, then we consider there will be little prospect of such a person, if the publication occurs after the date of this judgement, escaping a very substantial custodial sentence without there being a prospect of suspension. We hope that message will be clear.”

Attorney General Dominic Grieve, who is said to be considering proceedings against other offenders, has previously declared his intent to challenge the misconception that “so long as something is published in cyberspace there is no need to respect the laws of contempt or libel”.

“An internet posting takes seconds but can have major consequences,” he said. “It is irrelevant whether the postings in this case were of who they claimed to be. The order is meant not only to protect Venables and Thompson but also those members of the public who have been incorrectly identified as being either of them.”

The court heard that tens of thousands of people – 24,000 on Facebook alone – shared images said to be of adult Jon Venables and Robert Thompson in February this year. The pair, who were ten when their murder of two-year-old Bulger caused widespread revulsion in the country, were given new identities upon their release from custody and a ban was imposed on publishing anything that would identify them or their whereabouts. Yet the injunction was ignored by thousands on the internet.

Among them were Mr Harkins, 35, who reposted images on his Facebook site, and Mr Liddle, 28, who put them on his Opinionated Dad Twitter feed.

Mr Grieve decided to take a High Court case, applying for an order of committal against the pair, as a matter of public interest and because they had both shown from their posts that they were fully aware of the ban.

On his Facebook page with 141 friends, Mr Harkins, from Bridlington, wrote: “Intresting (sic) that this photo isn't allowed to be shown and there's an investigation on how it got out.”

Mr Liddle, a graphic designer from Sunderland who was said to be a key carer for his deaf son, had removed the photographs within an hour after being told that they were of the wrong people. But, upon being served with court papers from the Treasury Solicitor's Department after a member of the Attorney General's office spotted his original tweets, declared to his 915 followers: “Love them to take me to court. I'll tell them exactly why I posted pictures of sick child killers.”

Both men looked considerably less defiant as they were brought before the High Court, which heard that they had removed the images immediately, apologised for their behaviour and admitted being in breach of the injunction as soon as they were advised by solicitors. Neither, their barristers said, had realised the severity of their act of the potential for a two-year jail sentence.

Mr Harkins, the main carer for his three children while his wife worked at a pharmaceuticals store, accepted that he had been “grossly foolish”. Like Liddle, he said he had seen the images posted elsewhere hundreds of times but the judges said that was no excuse.

Sir John said that both men, in posting the pictures, knew of the danger of “serious physical harm or death” faced by Venables and Thompson, as well, as those who were mistaken for the two killers.

“Noone should contemplate taking the law into their own hands by encouraging the punishment of offenders by others,” the judge said. “Vigilantism has no place in a civil society and it is for the purposes of deterring such conduct that we must have particular regard.”