In September 2006, in a near-empty church in Ravenna, in north-east Italy, I found myself in front of a vibrant, 1,500-year-old mosaic of a woman in purple. She had a halo, her own courtiers, and was taking up an enormous space beside a mosaic of Christ. I knew she had to matter. At the gift shop, I bought the booklet about her, which took five minutes to read. The woman was the empress Theodora and although I had never seen her before, she has come to dominate my working life

Theodora lived in an era of huge changes in the church, language and statehood. What had been Roman was about to become Byzantine, and the eastern regions around Syria, the Levant and Egypt were clamouring to use their own languages, hinting at self-determination. Just 20 years after Theodora's death the Prophet Muhammad would be born.

Despite the huge amount of history written about the period, Theodora was largely overlooked. In Procopius's Secret History, which current studies believe was written not long after her death in 548, she is a kind of Mrs Machiavelli. He calls her "Theodora-from-the-Brothel", lasciviously details her antics on stage – from allowing geese to peck grain from her lower torso, to dancing naked but for a ribbon – and has her saying she regrets God gave her only three orifices for pleasure. When he goes on to describe her husband, the emperor Justinian, as a headless demon, we can assume not everything he wrote was utter truth.

Procopius's view on Theodora, which was not published until the 17th century, certainly influenced later writers, yet she remains an enigma. What we do know about her seems fascinating, often highly modern, apparently feminist, and almost always controversial. The more I read, the more I realised she was an ideal candidate for fiction, and for the last three years I have been writing a novel about her. She was born to the bear-keeper of Constantinople's hippodrome in about AD500. Her father died when she was five and her mother married another animal-keeper. When he failed to land her dead husband's job, she rehearsed her three little girls in arm movements and the silent gestures of supplication that would have been recognised by theatre audiences of the time. Then, she dressed them up and took them to the hippodrome – a vast complex, housing a capacity crowd of 30,000 men – to formally request a job for their new stepfather. The wish was granted and Theodora went on to become an actress, dancer, mime artist, comedian.

By the age of 15, she was the star of the hippodrome, performing in shows which, if Procopius is to be believed, were not far from the extremes of modern burlesque. She was also, as most actresses then were, a child prostitute. (That the word actress can have a derogatory aspect – having once been a synonym for "courtesan" or "whore" – has been long recognised, which is why many women who work in the theatre prefer the term "actor".)

Theodora had a child at 14, and her older sister Comito, a famed singer, likely became mistress to several wealthy men; it's probable that both had several abortions. At 18, Theodora walked away from her astonishing career, to become mistress to Hecebolus, the governor of what is now known as Libya. When they broke up, not long afterwards, she joined an ascetic community in the desert near Alexandria, experiencing a religious conversion to a branch of early Christianity, Monophysitism, that was then under attack by the Roman state. The division between those who believed, with the state, that Christ was both fully human and fully divine in one, and those who, as Theodora did, believed His divinity was the prime force, raged on throughout Theodora's life. After her conversion, she travelled on to Antioch and is reputed to have worked with Macedonia, a woman a little older than her who was a dancer, but possibly also a spy. Antioch was the major city of Syria, one of the many provinces that were starting to question the supremacy of Constantinople – there would have been good work for spies on all sides.

At 21, Theodora returned to the capital and met Justinian. They were certainly not a likely couple. Justinian was a farmer's son from present-day Serbia who travelled to Constantinople at the age of 11 to work for his uncle Justin, and help in his rise to power and eventual elevation to the throne. Justinian had a strong legal mind (his codifying of Roman law remains a part of legal training today), and had one law changed to raise Theodora's status, and another created to allow her to marry, something that former actresses could not legally do at the time. They married against the wishes of Justinian's aunt, the empress Euphemia, herself an ex-slave and concubine, who saw her own origins echoed a little too obviously in Theodora's. When Justin died and Justinian became emperor in 527, "Theodora-from-the-Brothel" was empress of Rome.

The classic rags to riches story is made richer still by Theodora's achievements in power. As empress, she worked on the paper On Pimps, an attempt to stop pimps making their money from prostitutes. Well aware of the impossibility of marriage and a safe life for such women, she set up a house where they could live in peace. Theodora worked for women's marriage and dowry rights, anti-rape legislation, and was supportive of the many young girls who were sold into sexual slavery for the price of a pair of sandals. Her laws banished brothel-keepers from Constantinople and from all the major cities of the empire.

All of which makes Theodora sound like an early and ardent feminist, but her story is more complicated. There are hints that she was involved in poisoning, torture and forced marriage, and while she did a great deal to help women and girls in difficulty, she had rather less time for women of higher standing – attacking any who threatened her position, including the empress Euphemia.

There are so many questions in Theodora's story. Was she a spy or a saint, a slut or a theatrical genius? What actually happened with the geese on stage at the hippodrome? Was Macedonia her friend or her lover? Theodora is the kind of hero you couldn't make up without being accused of overdoing it, and yet you can't tell her story without making a lot of it up. A perfect balance for fiction.

Theodora: Empress, Actress, Whore, by Stella Duffy, is published by Virago (rrp £15.99). To order a copy for £12.99 (including UK mainland p&p), go to theguardian.com/bookshop or call 0330 333 6846