The year 1869 had not been kind to young Mr Ernest Boulton who generally preferred to call himself – or herself – Stella.

In fact, 1869 had been decidedly cruel, beginning with Stella's startling discovery of a brazen and heartless infidelity on the part of her caro sposo, Lord Arthur Clinton, with none other than her best friend – and beloved sister – Mr Frederick Park, who generally preferred to be called Fanny. It had, according to Lord Arthur, only happened once. But once was enough. Of course, Stella blamed Fanny. Arthur was easily led and it was not the first time he had had his head turned by the tricks and wiles of a designing and unscrupulous young man dressed in women's clothes, as Stella now thought of Fanny.

It was a bitter blow. There had been tears, tantrums, scenes and slappings. Arthur was devastated and appalled. Fanny could only hang her head in shame and beg Stella's forgiveness. But Stella was adamant. She renounced her husband, disowned her sister and did what all sensible married women should do in such circumstances: she went home to her mamma in Peckham Rye.

But Stella felt increasingly restless there. Having been mistress of her own establishment, such as it was, with Lord Arthur, it was hard for her to bow to the superior claims of her mamma to be mistress in her own house. So when, in late September, her former paramour, Mr Louis Hurt, invited her to spend a few months with him in Edinburgh for a change of air, Stella accepted with alacrity. However dark, damp and dour Edinburgh in the winter might be, at least she would be free, like a bird released from a gilded cage.

There were times when Stella questioned whether she had done the right thing in giving Louis up. There was much to recommend him. He was tall, handsome and from a good family. Like Arthur, he had been educated at Eton but, unlike Arthur, had made his own way in the world and was now an Inspector of Post Offices. He was hard-working, sensible and solvent. His prospects were good and, most importantly, he was utterly devoted to her.

But, in truth, Louis was more than a little dull. He was strict and strait-laced. He did not approve of her career. He did not approve of drag. He did not approve of her campish ways. He did not approve of her working as a prostitute. He did not approve of unpaid bills, unmade beds, dirt, disorder or disarray. Louis was reluctant to call her Stella. He called her Ernest, or Ernie, but never Stella. And, although he never exactly put it into words, Stella sensed that he disapproved of her friendship with Fanny. All he wanted her to do was behave herself, conform, grow her moustache, be more manly and masculine and be Ernest Boulton, the beloved boy of Louis Hurt.

Stella's worst fears about Edinburgh were not fully realised. It was certainly dark, damp and dour, but it was also austerely beautiful, and the cold winds from the North Sea were refreshing and invigorating after the fug and smog of London. Louis had been there for a year or more and had comfortable chambers in Princes Street. Mrs Dickson, the landlady, seemed a good soul, and mercifully there was none of that poking and prying about of uppity servant girls that had so plagued Stella at Lord Arthur's.

However, there was bound to be a fly in the ointment and the people who lived above were being tedious, as people who live above generally are, and had complained about the noise of the piano, most especially about Stella "playing weekday tunes on the Sabbath", and Mrs Dickson had tactfully requested she "leave it off on a Sunday".

Stella had only to set foot in the streets of Edinburgh to draw gasps and stares. Many, but by no means all, of these were hostile. The rest were bewildered, curious, frankly interested and downright flirtatious. Stella revelled in the attention.

"Nothing like him had ever been seen in Edinburgh before," Mr John Doig, a colleague of Louis's, declared. "He was spoken about a great deal, and a number of people expressed doubts about his sex."

There was no shortage of gentlemen callers. Stella's debut in Edinburgh caused quite a stir in certain circles and she was besieged on all fronts by beaux. Finally there was Mr John Safford Fiske, the handsome and charming United States consul in Leith, who was as fine a specimen of American manhood as Stella had yet met.

But he had a plan. He wanted to marry, and marry well. He needed a wife with a fortune to place at his disposal so that he could fulfil his political ambitions to become a United States senator, or even president. His present means were more than adequate to meet his needs, but even in the great democracy of the United States, it was money that talked the loudest. The fastest and easiest way to acquire money, and lots of it, was to marry.

In fact, Mr John Safford Fiske was on the brink of surrendering himself to matrimony with a young American bride of impeccable pedigree and a very large fortune, who was coming to Edinburgh so their engagement could be announced. Of course there would be curbs on his freedom. As a married man, he would have responsibilities towards his bride but, as soon as the children came, he hoped he might be left to pursue his other sexual interests.

Mr John Safford Fiske's attitude to marriage was modelled on that of the Ancient Greeks: women for duty, but boys for pleasure. "After we were married I could do pretty much as I pleased," he mused. "People don't mind what one does on £30,000 a year, and the Lady wouldn't much mind as she hasn't brains enough to trouble herself about much beyond her dresses, her carriage etc."

From the moment of his arrival in Edinburgh, Mr John Safford Fiske had sought out "adventures", as he called them, and had established a delightful network of charming and handsome young men – or so it was until the fateful moment when Stella Boulton swept into Edinburgh like the devouring north wind and turned his world upon its head.

There were women, there were men and then there was Miss Stella Boulton. Mr John Safford Fiske had never before met anyone like her and he knew he would never do so again. She was fascinating, compelling. She seemed to him to be half-man and half-woman, but more, infinitely more, than the sum of her two parts.

Stella was "Laïs and Antonious in one". An amalgam, a coalescence, of Laïs the Corinthian, the most famous, beautiful and expensive courtesan of the Ancient World, the muse of Demosthenes, and Antonious, the most beautiful and beloved boy of the Emperor Hadrian. It was, he wrote, "a ravishing thought".

Who could fail to fall in love with two such beings, united in one perfect body?

Mr John Safford Fiske was powerless to resist. It was more than love, than lust. It was a kind of madness, a rapture. He could not sleep or eat. Thoughts of Stella, in or out of drag, as a man, a woman or an hermaphrodite, filled his waking and sleeping hours. He wanted Stella more than anything else. More than a wife and fortune. More than power and glory. More, perhaps, than life itself. He knew only too well that the more he wanted her, the more he risked all. But he was prepared to give up everything for her.

Perhaps Mr John Safford Fiske should have been careful of what he wished for: within weeks, Stella, along with Fanny, had been arrested in drag while out on a jaunt in London. On June 9, 1870, there was a loud rap at Mr John Safford Fiske's chambers at 136 George Street, Edinburgh. On the doorstep stood Detective Officer Roderick Gollan of the City Police with a warrant for his arrest.

Ernest 'Stella' Boulton, Frederick 'Fanny' Park, John Safford Fiske, Louis Hurt and others would face a state trial for their high crimes before the Lord Chief Justice in Westminster Hall. If convicted, they faced imprisonment for life.

Neil McKenna's Fanny And Stella: The Young Men Who Shocked Victorian England is published by Faber (£16.99). McKenna will be talking at Waterstones West End, Edinburgh, on February 21 at 6pm. Free tickets are available in advance. Call 0131 226 2666