Former News of the World editor Andy Coulson has been cleared in his perjury trial.

Coulson, 47, had been on trial for around two weeks at the High Court in Edinburgh, where he denied committing perjury during the 2010 case in Glasgow.

Trial judge Lord Burns upheld a defence motion that Coulson, from Kent - a former director of communications for the Prime Minister - had no case to answer.

Delivering his ruling, Lord Burns said he had "sustained the arguments in favour of the accused" and told Coulson: "I acquit you of the charge."

He gave his decision on Monday following two days of legal submissions from Mr Coulson's defence QC but it could not be reported until today as the Crown was given time to decide whether to appeal against the ruling.

Coulson was found guilty in June last year of conspiring to intercept voicemails at the now-defunct Sunday tabloid following a trial at the Old Bailey.

During the perjury trial, the Crown led evidence from several former journalists at the paper as they tried to build a picture of practices while Coulson was editor - a position he held from January 2003 until his resignation in January 2007.

But when the prosecution closed its case after seven days of evidence last Tuesday, Mr Coulson's legal team lodged a submission that there was no case to answer and among the arguments said the evidence alleged to be false in this case was not relevant to the then live issues - the charge of perjury in Mr Sheridan's trial.

The prosecution case centred around what they alleged to be lies told by Coulson under oath at Mr Sheridan's trial more than four years ago.

Mr Sheridan was on trial for perjury at that stage and, while conducting his own defence, called Coulson as a witness over two days at the High Court in Glasgow in December 2010.

Mr Sheridan's trial was in respect of evidence he gave in an earlier 2006 civil action.

Coulson's trial heard that, following publication of a series of articles in the News of the World, Mr Sheridan raised a defamation action in Scotland's Court of Session against the newspaper's publishers, News Group International.

The jury in the subsequent 2006 action decided that the politician had been defamed by the newspaper and it was ordered to pay him £200,000 in damages.

Mr Sheridan was jailed for three years in January 2011 after being found guilty of lying about the now-defunct tabloid's claims that he was an adulterer who visited a swingers club.

Prosecutors in the latest trial alleged that Coulson made false claims on December 9 and 10 2010 after being sworn in as a witness in Glasgow.

The charge against Coulson alleged he falsely stated that before the arrest of private investigator Glenn Mulcaire and News of the World journalist Clive Goodman on August 8 2006, he did not know that Goodman was involved in phone hacking with Mr Mulcaire.

It claimed he falsely said he did not know that payments were made to Mr Mulcaire by Mr Goodman and he did not know of Mr Mulcaire's "illegal activities".

The Crown also alleged that Coulson was wrong when he said he did not have any email exchanges with Goodman in relation to Mr Mulcaire and falsely stated that he did not know of Mr Mulcaire, had not heard his name and did not know that he was employed by the tabloid.

Coulson pleaded not guilty to the allegations against him.

A recording of the evidence Coulson gave in Mr Sheridan's court case was played to the jury of nine men and six women.

The jurors heard him tell Mr Sheridan that he had stepped down from the role of editor after Goodman was convicted of phone hacking.

On the 2010 tape he was heard saying he "had no knowledge" of phone hacking but chose to resign as he felt he "had to take responsibility for it".

"Things went badly wrong at the News of the World under my editorship and that's why I quit," Coulson said on the tape.

The court also heard from senior journalists at the paper at the time Coulson was in charge.

They included Goodman, a one-time royal editor at the tabloid, who pleaded guilty to phone-hacking offences in 2006.

Next up was Neville Thurlbeck, the paper's one-time chief reporter, followed by James Weatherup, a past news editor at the tabloid.

In subsequent legal argument which could not be reported until now, defence QC Murdo Macleod told the judge: "It's not a hacking trial, it's a trial about perjury."

Without the jury being present, Mr Macleod said that in order to constitute perjury, the evidence alleged to be false must have been relevant to the original trial.

He pointed to the defence's closing speech in 2010, in which Mr Sheridan said: "The reason I risked my defence to cite the likes of ... Andy Coulson to give evidence wasn't because I thought they were going to help my defence, it was because I think I have a public service and a public duty to try and expose wrongdoing..."

Mr Macleod called this section of his speech a "clear demonstration of irrelevance".

"It's as plain as a pikestaff," he said.

Mr Macleod said what the Crown "could not get away from" was that Mr Sheridan and the advocate depute in the original trial "had deemed Mr Coulson's evidence as irrelevant".

However, prosecutors argued that the evidence was relevant because the defence in the original proceedings had taken a position that practices at the News of the World, including hacking, could have allegedly facilitated the manufacture of a disputed video tape which was entered as evidence in Mr Sheridan's trial.

The Crown argued that the questioning of Coulson on whether he knew about hacking was in order for the defence to support that position and therefore relevant to its case.

But the defence pointed to the agreed facts in this trial that there was no evidence led of any unlawful interception of messages left on Mr Sheridan's phone during the original trial.

Mr Macleod said the Crown could not "ride two horses" and say evidence was irrelevant in the original trial, and then later rely on it as relevant in this trial.

"Not only is he (the Lord Advocate) seeking to ride two horses, the two horses are galloping in opposite directions," Mr Macleod said.

Lord Burns told Coulson today: "You may leave the dock."

Coulson walked to the back of the courtroom and sat down to listen to the judge discharge the jury.

Lord Burns told jurors he would explain what had happened on the days they were not in court.

He said: "To prove the charge against Mr Coulson, the Crown needed to prove that the allegedly false evidence given by Mr Coulson was relevant to the issues which arose in Mr Sheridan's trial for perjury or Mr Coulson's credibility in the important evidence he gave at that trial.

"That was the matter of law for me. A judge's question. Relevancy is always a judge's question."

He told them: "After two days of legal submissions last week and having considered the matter, I decided that the Crown had not led sufficient evidence to satisfy me that the allegedly false evidence was relevant to proof of the charge in Mr Sheridan's trial or Mr Coulson's credibility at that trial."

Following today's hearing, a Crown Office spokesman said: "Andrew Coulson was a defence witness at the trial of Tommy Sheridan. He gave his evidence without objection as to relevancy.

"The Crown indicted Coulson on the basis that he lied during parts of his evidence, in particular that he had no knowledge of phone hacking.

"The trial judge in the Coulson trial, at the conclusion of the prosecution evidence, ruled that this evidence was irrelevant and therefore could not found the basis for a prosecution for perjury.

"This brings proceedings to an end."

In his written decision, Lord Burns said: "I consider that the false evidence alleged in this indictment was not relevant evidence at the original trial and the charge of perjury in the indictment is irrelevant."

Speaking outside court Coulson said: "I am obviously delighted by the judge's decision today. It was the right decision. I would like to thank him, I would like to thank the jury for their patience and I would like to thank my brilliant legal team.

"This prosecution was always wrong. I didn't lie and the prosecution, in my view, was a gross waste of public money.

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

The Prime Minister's official spokeswoman confirmed that David Cameron was aware of the decision, adding: "It is a matter for the court."

Asked at a regular Westminster media briefing whether the PM would offer Coulson his old job back, the spokeswoman said: "He has got a director of communications, who indeed is taking on a broader role in Number 10."