Two women are holding a man down on a bed. One presses her fist against his head, so he can’t raise it from the mattress, while her companion pins his torso in place. They are well-built with powerful arms but even so it takes their combined strength to keep their victim immobilised as one of them cuts through his throat with a gleaming sword. Blood spurts from deep red geysers as she saws. She won’t stop until his head is fully severed. Her victim’s eyes are wide open. He knows exactly what is happening to him.

The dying man is Holofernes, an enemy of the Israelites in the Old Testament, and the young woman beheading him is Judith, his divinely appointed assassin. Yet at the same time he is also an Italian painter called Agostino Tassi, while the woman with the sword is Artemisia Gentileschi, who painted this. It is, effectively, a self-portrait.

Two big, blood-drenched paintings of Judith and Holofernes by Gentileschi survive, one in the Capodimonte in Naples, the other in the Uffizi in Florence. They are almost identical except for small details – in Naples Judith’s dress is blue, in Florence yellow – as if this image was a nightmare she kept having, the final act to a tragedy endlessly replaying in her head.

With words and images, she fought back against the male violence that dominated her world

“This is the ring you gave me and these are your promises!” yelled Gentileschi as she was tortured in a Rome courtroom in 1612. Ropes were wrapped around her fingers and pulled tight. The judge had advised moderate use of the sibille, as this torture was called, for she was after all 18. Across the court sat the man who had raped her. No one thought of torturing him. Defiantly, Gentileschi told him her thumbscrews were the wedding ring he’d promised. Again and again, she repeated that her testimony about the rape was reliable: “It is true, it is true, it is true, it is true.”

Gentileschi was the greatest female artist of the baroque age and one of the most brilliant followers of the incendiary artist Caravaggio, whose terrifying painting of Judith and Holofernes influenced hers. She is one of the stars of Beyond Caravaggio, an epic survey of his rivals and disciples about to open at the National Gallery in London. With words and images, she fought back against the male violence that dominated the world she lived in.

Gentileschi achieved something so unlikely, so close to impossible, that she deserves to be one of the most famous artists in the world. It is not simply that she became a highly successful artist in an age when guilds and academies closed their doors to women. She also did what none of the other – rare – Renaissance and baroque women who made it as artists could manage: she communicated a powerful personal vision. Her paintings are self-evidently autobiographical. Like Frida Kahlo, Louise Bourgeois or Tracey Emin, she put her life into her art.

And what a brutally damaged life it was. In the wild art world of Caravaggio’s Rome, artists were rich, arrogant and could do almost anything they liked so long as they stayed in the pope’s good books. Gentileschi must have met Caravaggio many times as a child: perhaps he even encouraged her to paint. Her father, Orazio, also a talented artist, was Caravaggio’s close friend. In 1603, Orazio and Caravaggio were up in court together after they scrawled libels about some enemy artist in the streets of Rome. In his evidence, Orazio casually mentioned Caravaggio coming round to his house to borrow a pair of angel wings.

Evidence of trauma … Susanna and the Elders by Gentileschi. Photograph: © The Burghley House Collection

This gives us a lovely snapshot of Gentileschi’s childhood: the great Caravaggio popping by for props. Born in 1593, she was 10 when that happened. When she was 13, disaster hit Caravaggio’s circle. He was always on the edge of danger – he carried a sword and was ready to use it – but in 1606 he killed a man who had friends at the papal court. He fled. Orazio and his daughter would never see their inspiration again.

Being the daughter of an artist was the only way a young woman could hope to learn the complex skills it took to paint professionally in the baroque age. It seems that Orazio had ambition for his daughter – after all, he gave her a striking, classical name. And as her skill developed, he hired an upcoming artist, Agostino Tassi, to give her lessons. Then, in 1612, Orazio accused Tassi of raping his daughter, as well as tricking her out of a painting from his studio.

The resulting trial lasted seven months and shocked Rome. It made Gentileschi a celebrity – in the worst possible way. Amazingly, every word of this court case survives, in a transcript that opens a window on to the lives of artists in the age of Caravaggio. Gentileschi speaks to us from this 400-year-old document with a voice that is eloquent, courageous and compelling. It is a rare example of a woman in the pre-modern era taking a stance against the oppression that was just part of day-to-day life.

I pulled his hair, she told the court, and grabbed his penis so tight I even removed a piece of flesh

Tassi tricked his way into her room and started making unwanted offers of sex, she testified. “He then threw me on to the edge of the bed, pushing me with a hand on my breast, and he put a knee between my thighs to prevent me from closing them. Lifting my clothes, he placed a hand with a handkerchief on my mouth to keep me from screaming.”

She fought back. “I scratched his face,” she told the court, “and pulled his hair and, before he penetrated me again, I grasped his penis so tight that I even removed a piece of flesh.” But she couldn’t stop him. Afterwards, she rushed to a drawer and got out a knife. “I’d like to kill you with this knife because you have dishonoured me,” she shouted. He opened his coat and said: “Here I am.” Gentileschi threw the knife but he shielded himself. “Otherwise,” she said, “I might have killed him.”

The trial also featured months of meandering witness examinations. Friends, tenants, artists and relatives built up a picture of Gentileschi’s household. She is portrayed as a teenager who spent all her time painting, rarely going out. Her rapist, meanwhile, emerged as an even worse character than he first seemed. Several witnesses claimed he had murdered his wife – and he could offer no good defence.

Yet Gentileschi was tortured and Tassi was set free. Why? He was protected by the pope, because his art – forgotten today – was rated at the time. Everyone knew he was a villain. “Tassi is the only one of these artists who has never disappointed me,” said Pope Innocent X. Other artists pretended to be men of honour, he explained, but let him down. With the irredeemable Tassi, he knew where he stood.

Gentileschi, still a teenager when the trial ended, was shamed in a culture where honour was everything. Yet it also provided a kind of monstrous publicity. By the 1620s, she was a successful artist working as far from Rome as she could get. And she was taking revenge with the only weapon she had: a paintbrush. She could not write her story because, as she revealed during the trial, she was more or less illiterate. She could paint it, though, and change its ending – as her paintings of Judith and Holofernes show.

Gentileschi, however, brings out an element of the biblical story no male artist had ever dwelt on. In most paintings, including Caravaggio’s hallucinatory rendering, Judith has a servant who waits to collect the severed head. But Gentileschi makes the servant a strong young woman who actively participates in the killing. This does two things. It adds a savage realism that even Caravaggio never thought of – it would take two women to kill this brute. But it also gives the scene a revolutionary implication. “What,” wonders Gentileschi, “if women got together? Could we fight back against a world ruled by men?”

Armed with a brush … Self-portrait as the Allegory of Painting, by Gentileschi. Photograph: Royal Collection Trust

Beyond Caravaggio will showcase another Gentileschi work, her 1622 painting of Susannah and the Elders. Here, again, she uses a biblical story to dramatise what it was to be a woman in the 17th century. Two old men are spying on a young woman bathing, but Gentileschi heightens the creepiness by having the men come right up and openly stare, while other artists tend to show them hiding at a distance. Why does she show the voyeurs as totally unembarrassed, making no attempt to conceal their lust and intruding on Susannah’s space?

It is a disturbing effect, strangely reminiscent of her own persecution. In the, trial, it emerged that Tassi had an accomplice who also lusted after her. They both kept hanging around, bugging her, watching her, just like the voyeurs troubling Susannah. The trauma of Gentileschi’s rape and the trial that gave her no justice haunt her art. Yet she was not crushed by her suffering. On the contrary, the visceral power of her paintings made her one of the most famous artists in Europe.

Even the far-off British court had heard of her. In 1638, Charles I personally invited her to London to work for him. There, Gentileschi painted what may be her most original and important work. In her Self-Portrait as the Allegory of Painting – on show next month at the Queen’s Gallery in Buckingham Palace in an exhibition called Portrait of the Artist – she depicts herself as a muscular, dynamic, forceful character, like the women who hold down Holofernes. Instead of a sword, she’s armed with a brush. Centuries before feminism, Gentileschi moves through space with extraordinary fluency, the maker of her own image, the hero of her own life.