Former News of the World editor Andy Coulson has been acquitted by a Scottish court of committing perjury by lying about his knowledge of phone hacking at the Rupert Murdoch-owned tabloid he once edited.

Coulson, who was editor of the now-defunct newspaper from 2003-2007, was jailed last July for conspiracy to intercept voicemails on mobile phones after it was revealed there had been widespread hacking by journalists to obtain exclusive stories for his paper.

He had been accused of lying under oath when he appeared at a trial in Glasgow in 2010, when he told the court he had no knowledge of illegal activities by his reporters.

Coulson, who was also British prime minister David Cameron's one-time media chief, was answering questions over a front-page News of the World story about a Scottish socialist politician, Tommy Sheridan, whom the paper accused of visiting a swingers' club.

Sheridan won a defamation action against the paper in 2006 but was found guilty of perjury at the 2010 trial and jailed for three years.

On Wednesday, the High Court in Edinburgh threw out the charge of perjury against Coulson in relation to the Sheridan case after the judge ruled there was no case to answer.

Under Scottish law, a lie is only perjury if it affects the verdict, and the judge ruled Coulson's evidence had not been relevant in the case against Sheridan so whether he had told the truth or not did not matter.

Coulson said afterwards: "This prosecution was always wrong. I didn't lie. The prosecution in my view was a gross waste of public money."

"I'm just delighted after four pretty testing years my family and myself have finally had a good day."

Coulson quit News of the World after phone hacking first came to light when the paper's royal editor and a private detective were jailed for accessing the phones of royal aides.

Within months, he went to work for Mr Cameron, but when the scandal resurfaced in 2011 he resigned as the prime minister's communications chief.

Mr Murdoch closed the 168-year-old News of the World in July that year amid a public furore that reporters had hacked into a murdered schoolgirl's phone.

Before its collapse, Coulson's perjury trial was told by convicted former News of the World journalists that their former editor was well aware that hacking was commonplace on the paper.

Coulson, who served 20 weeks behind bars after last year's phone-hacking conviction, could have faced years in prison if he had been convicted of the perjury offence.

Reuters