Judge Howard Riddle ordered the publisher of the Spectator to pay a fine of £3,000, plus £2,000 in compensation for distress to Lawrence's parents, in a hearing at Westminster magistrates' court in central London on Thursday morning.

The Spectator pleaded guilty to breaching a court order with the Liddle article, published in November 2011 at a key moment in the trial.

Fraser Nelson, the editor of the magazine, was in court for the short hearing. He declined to make any comment to reporters outside court.

Alison Morgan, the lawyer for the Crown Prosecution Service, told the court that the Spectator should face the maximum possible penalty because the "potential for harm could not have been greater" from the publication of the article.

"The potential for this article to have devastating consequences [for the trial] was of the top order," the prosecutor said.

The judge took the unusual step of directing the Spectator to pay compensation to Lawrence's parents even though it had not been requested. The Spectator may not have to pay the £2,000 compensation if it is rejected by the Lawrence family.

Riddle said the Spectator would have faced the maximum possible fine – £5,000 – for breaching the court order, but added that it was lowered due to the magazine's swift apology and removal of the article from the internet.

He said that the article caused a brief moment where the trial of Lawrence's killers was in jeopardy. "For Mr and Mrs Lawrence the prospect of the trial collapsing must have been agonising," he added.

Brian Spiro, the lawyer representing the Spectator, told the court that a "unique and unfortunate" series of events led to an "unprecedented and bitterly regretted" failure of the weekly current affairs magazine's internal legal process that meant the article was published.

The court heard that neither Nelson nor the senior lawyer responsible for checking Spectator articles were in work on the day the Liddle article was sent to print.

Liddle believed his article was within the law but the former Today programme editor was not fully aware of the fresh reporting restrictions in place for the trial, Spiro told the court.

The article claimed the two defendants would not get a fair trial. Liddle wrote that Dobson and Norris had already been presented as violent racists and any judge who took action against him for saying so was "singularly perverse", the court heard.

"On 24 November 2011 the attorney general referred an article published in the Spectator magazine to the Crown Prosecution Service for consideration of whether a reporting restrictions order in place at the time had been breached," Saunders added.

"The article in question was dated 19 November 2011 and came during the trial of Gary Dobson and David Norris who were accused, and subsequently convicted, of the murder of Stephen Lawrence. The judge, Mr Justice Treacy, referred the article to the attorney general for consideration under his contempt powers."

Under section 83 of the Criminal Justice Act 2003, where publication is in a newspaper or periodical, the proprietor, editor or publisher may be liable for an offence but not the author.

• To contact the MediaGuardian news desk email editor@mediaguardian.co.uk or phone 020 3353 3857. For all other inquiries please call the main Guardian switchboard on 020 3353 2000. If you are writing a comment for publication, please mark clearly "for publication".

• To get the latest media news to your desktop or mobile, follow MediaGuardian on Twitter and Facebook

More on this story

Still ranting about capitalism, political correctness, broken families, the Guardian and especially the liberal elite, Rod Liddle says he's a better man now at 54 than he's ever been. He even apologises for being negative, writes Simon Hattenstone