A self-obsessed salsa dancer who became personal interpreter to Britain's top general in Afghanistan was jailed for 10 years yesterday for spying for Iran.

Daniel James, of Brighton, had access to the highest echelons of the Nato mission in Kabul and was "caught red-handed" as he betrayed his country in a series of coded e-mails.

But the 45-year-old's lawyer said commanders should have realised the flamboyant Iranian-born Territorial Army corporal was "potential dynamite".

Mr Justice Roderick Evans agreed he should never have been placed in such a sensitive position.

However, a Ministry of Defence spokesman said Mr James had been security cleared "to an appropriate level".

The self-important corporal styled himself "General James" and believed he had been passed over for promotion because of racism and jealousy.

But his treachery could have cost the lives of British soldiers and prosecutor Mark Dennis, QC, said it was "the height of betrayal".

James worked for General David Richards, who has since been appointed the next head of the British Army, and at the time headed the Nato-led International Security and Assistance Force (ISAF), a 37-nation coalition comprising 35,000 troops.

The judge told James: "The gravest part of your offending and what made this case unique was that you engaged in this activity when you were actually serving in a war zone.

"You were in a theatre of war. Your colleagues and companions were at daily risk of being injured or killed."

The judge also said James was a "ripe target" for the Iranians because of his nationality, disenchantment with the Army and "narcissistic" personality.

Colin Nicholls, QC, defending, said he should never have been given such a sensitive position, telling the judge: "He would not be here if people had been more careful, realising effectively that this man was potential dynamite."

Jurors heard James was an extrovert with "somewhat grandiose ideas about himself and his own self-importance", and a "Walter Mitty character" who would be likely to find his new clandestine role as a spy "exciting and special".

During his time as a corporal, James mixed freely with military top brass and in August 2006 met Colonel Heydari at the Iranian embassy.

He began sending the colonel coded e-mails in a bid to prove his credentials as a mole at the heart of ISAF headquarters and told him: "I am at your service."

Jurors heard that his relationship with his Iranian contact was "nipped in the bud" after he was arrested.

But the judge yesterday said he had no doubt that if it had been allowed to develop it had the potential for causing "serious harm".

James's actions had damaged the relations between Nato governments, whose "mutual trust" in sharing sensitive information was "essential for protecting the lives of British soldiers", he added.

James, who came to Britain from Tehran as a teenager, was convicted under the Official Secrets Act of communicating information useful to an enemy, by an Old Bailey jury earlier this month.

A second charge, relating to sensitive documents stored on a memory stick found in his possession, and a third count of misconduct in public office, were allowed to lie on file after jurors failed to agree verdicts.

James was told he would serve half his 10-year jail term in custody, minus the 709 days he has already been on remand, before being released on licence.