A Royal Navy petty officer who offered nuclear submarine secrets to MI5 agents posing as Russian spies has been jailed for eight years.
Edward Devenney, 30, originally from County Tyrone, gathered classified coding material after being passed over for promotion, the court was told.
He had been "prepared to betray his country and his colleagues", said Mr Justice Saunders at the Old Bailey.
Devenney admitted breaching the Official Secrets Act.
He also admitted a charge of misconduct in a public office. He had been arrested in Plymouth in March.
Passing sentence, Mr Justice Saunders said: "The defendant made determined efforts to enter into an agreement to supply secret information to representatives of another country."
The court had "to mark the defendant's attempted betrayal of not only his country but also his colleagues, who must feel great anger at his behaviour", he said.
"While it can properly be said that the defendant achieved nothing and is unlikely to be in a position, even if he had the inclination, to pass on secret information in the future, others must be discouraged from behaving in a similar way.
"It needs to be understood by those who may be tempted to pass on secrets that long prison sentences must follow even unsuccessful attempts."
Mr Justice Saunders added: "Those who serve their country loyally must know that those who don't will receive proper punishment."
Devenney, who lived in Barnstaple, Devon, had contacted the Russian Embassy in November 2011 after what he said had been a 12-hour drinking binge.
Two days later, he managed to access a safe on nuclear sub HMS Vigilant and photograph part of a secret code for encrypted information.
Subsequently, MI5 agents recorded meetings at various venues, including the British Museum, in which Devenney said he was angry with the Navy and did not want payment for the information.
Also offering details of HMS Vigilant's movements, at one point Devenney told one of the contacts: "Your accent sounds remarkably fake and like British intelligence."
Devenney was arrested in Plymouth in March.
Mark Dennis QC, prosecuting, said: "The potential damage could have been considerable and could have harmed the safety and security of the United Kingdom."
Mari Reid, unit head of the Crown Prosecution Service counter-terrorism division, called the case "a classic story of betrayal".
"We rely on the men and women of our armed forces to keep us safe. It is hard to imagine a greater breach of that role than Devenney's actions."
At the time of the offence Devenney was drinking heavily, suffered bouts of depression and had just been cleared of rape, the court was told.
He had asked for his training course for promotion to be deferred for a year but was warned he faced the sack after prolonged absences without leave.
Lord Carlile, defending, said that Devenney had been "something of a blue-eyed boy" until the rape allegation had led to a deterioration in his behaviour.
He read a letter from Devenney to the court that said: "I have brought great shame to my family, loved ones and the submarine service.
"I accept the consequences of my actions and I'm truly sorry. Mostly I would like to apologise for the shame I brought on the Royal Navy."
Lord Carlile added that when the Royal Navy and Ministry of Defence reflected on events, "they might think twice about leaving a person in post until the issues have been resolved".