MI6 spy Gareth Williams tied himself to his bed and had to be cut free several years before his naked body turned up in a padlocked bag, his inquest has heard.
Mr Williams was working for GCHQ in Cheltenham when he was forced to cry out for help after attaching his wrists to his headboard in his rented flat.
His landlord and landlady rushed to his aid in the middle of the night after hearing him shout from the annexe to their home, where he lived. They found him bound to his bed and wearing only his boxer shorts, the hearing was told.
Embarrassed, panicky and apologetic, he explained to them he had been trying to see if he could escape, his landlady said. In a written statement read to London's Westminster Coroner's Court, Jennifer Elliot described the startling scene that greeted her and her husband three years before their former tenant's death.
He was not aroused and although his landlady could see "no sperm near him", she and her husband assumed the escapade was probably sexual rather than an attempt at escapology, she said. There was no repeat of the strange incident, Ms Elliot said, and she and her husband never spoke of it to anyone but each other.
Mr Williams's body was found locked in a holdall in the bath at his central London flat in Pimlico on August 23, 2010, but 20 months on his death remains shrouded in mystery.
Police who entered the apartment after he went missing found some £20,000-worth of high-end women's clothing and shoes among his possessions, the inquest has heard.
A member of staff who worked at upmarket west London fashion store Dover Street Market recalled him coming in regularly and buying women's items he said were for his girlfriend. In a written statement read to the court, Carol Kirton said the spy had never mentioned his girlfriend's name.
Elizabeth Guthrie, a friend of Mr Williams, was asked in court whether the spy had ever expressed an interest in cross-dressing. "Nothing of a sexual bent but we were going to a fancy dress ball together," she said. "He was going as a ninja, not as a queen."
Mr Williams had, however, visited websites about claustrophilia - the love of enclosure - and bondage and sadomasochism on his home computer, the court heard.