In 1809, during a bitter London winter, with the Napoleonic War at its height, a young Irishwoman set out on a course of deception which would fool the brightest and highest in the British Empire; dreading the confined life of a woman, she had decided to transform herself into a man.

Margaret Bulkley was 20 years old. She had been born in Cork in 1789 into a respectable family; her father, Jeremiah, had a shop on Merchant’s Quay which serviced the ships. It was a busy time, Cork being one of the main hubs of the British Empire’s vast network of trade and warfare. But following the 1798 rebellion and the Acts of Union which tied Ireland in bondage to Britain, Jeremiah lost his business and his small fortune through a mix of anti-Catholic repression and his own foolhardiness, taking on large loans to pay for the education of his wastrel son.

Margaret, who was brighter than her brother and had been brought up with middle-class expectations, was thrown into poverty; adding to her burden, in her early teens she was raped by an uncle and bore a child. Margaret and her mother fled to London, leaving Jeremiah to languish in Dublin debtors’ prison. They sought help from Margaret’s uncle, the great but eccentric painter James Barry, another son of Cork, who had established a reputation for both artistic greatness and madness.

When uncle James died, Margaret was taken under the wings of his intellectual friends, including General Francisco de Miranda, an exiled Venezuelan revolutionary. Margaret decided to use her modest inheritance for a remarkable purpose. With Miranda’s encouragement, she hoped to become a surgeon and go with him to Venezuela to fight in its war of independence. Of course, in the early 1800s it was unthinkable for a woman to study medicine, let alone practise. But Margaret, a young woman of intelligence, vision and daring, decided to disguise herself as a man. She adopted the name of her late uncle – James Barry – and set out for Edinburgh University. Amazingly, she was accepted and enrolled (her small stature and fresh-faced appearance were put down to her being very young).

It was a hard life, 16 hours a day of lectures, studying, practical classes and ward experience, as well as grisly dissections in insanitary conditions, all in an overwhelmingly masculine environment. However, James Barry prospered, and in due course he returned to London a qualified doctor. Within months he had passed for membership of the Royal College of Surgeons. And at this point Margaret made a fateful decision. Shedding her disguise and going to Venezuela was no longer an option – General Miranda had been betrayed by a friend and was now in a Spanish gaol. Instead, Margaret decided to keep James Barry in existence and join the British Army as a surgeon.

For the next half-century, Margaret Bulkley fooled the Army, high society, and the whole British Empire, from Jamaica to Malta, and from the Cape to the Crimea. Dr James Barry became a celebrated surgeon, a pioneer of new techniques (in 1826 he carried out the first successful caesarean delivery, a procedure which was invariably fatal for the mother in those days); he was a favourite in high society and private physician to the nobility. And although most people found the effeminate little doctor peculiar, nobody knew that beneath his immaculate scarlet coat he was a born woman.

Even if they had suspected something, they wouldn’t have believed it. According to the values of the day, it was inconceivable that a woman could master the intellectual challenges of medicine and surgery, let alone the physical ones; this was a time without anaesthetics, when surgical patients had to be held down, and amputation was a common treatment for fractures and infections. But Margaret Bulkley had mastered it all and excelled. Dr James Barry pulled the wool over the eyes of the British Army Medical Department and a large swathe of the British Empire’s great and good, from Queen Victoria to Lord Raglan and Florence Nightingale. Even Napoleon’s astute special adviser (who became a patient of Dr Barry’s during his captivity) was fooled.

The secret couldn’t last forever. Dr James Barry died in London in 1865. His standing instruction that he be buried in the clothes in which he died, without examination, was forgotten or ignored. A charwoman hired to lay out the body discovered the truth about his sex; at first she tried to blackmail the army, and when that failed she made the news public. It was first reported in Dublin in Saunders’s News-Letter, then spread across Britain and throughout the Empire.

Speculation about Barry’s motives and true identity was rife. Now, for the first time in 150 years, our new biography, Dr James Barry: A Woman Ahead of Her Time, using a wealth of archive material never previously considered, reveals the full story of Miss Margaret Bulkley, one of Ireland’s greatest daughters.

Her life as James Barry was a succession of audacious firsts – the first woman to become a doctor; the first to perform a successful caesarean delivery; a pioneer in hospital reform and hygiene; and the first woman to rise to the rank of general in the British Army (Barry’s commission, signed by Queen Victoria, still exists).

The stress of gaining all these achievements while maintaining her disguise had its effect on Margaret. James Barry became notorious for his irascible temper, his intolerance of contrary opinions, and his violent response when his disguise seemed under threat. On one occasion he slashed a fellow officer across the face with a riding crop for remarking on his effeminate appearance; on another he fought a famous duel in which he was wounded in the thigh (his opponent was hit square in the forehead by James’s bullet, but was saved by the peak of his hat).

As well as pioneering hospital hygiene and public health, Barry was a vigorous campaigner against slavery, and all the while helped push forward the frontiers of surgery. During the Crimean War he ran an exemplary hospital for convalescent wounded in Corfu, and clashed with Florence Nightingale at Scutari; it may be that, beneath her disguise Margaret was jealous of the praise heaped upon her female colleague for implementing hygiene and sanitation measures which Dr Barry had been practising for many years in obscurity. After the initial scandal of 1865, Barry returned to obscurity, although he is still remembered by many in his native Ireland.