The artist, says Kafka, is the one who has nothing to say. By which he means that art, true art, carries no message, has no opinion, does not attempt to coerce or persuade, but simply – simply! – bears witness. Ironically, we find this dictum particularly hard to accept in the case of his own work, which comes to us with all the numinous weight and opacity of a secret testament, the codes of which we seem required to decrypt. The Trial, we feel, cannot be merely the simple story of a man, Josef K, who gets caught up in a judicial process – the book's German title is Der Prozeß – that will lead with nightmarish inevitability to his execution. Surely it is at least an allegory of fallen man's predicament, of his state of enduring and irredeemable guilt in a world from which all hope has been expunged. Yet the book has its direct sources in the mundane though extreme circumstances of Kafka's own life, and specifically in what Elias Canetti calls Kafka's "other trial".

It is surprising at first to learn that Flaubert was Kafka's favourite writer, yet Kafka, as a moment's reflection will show, was every bit as strong a realist as the author of Madame Bovary or (the master's work that Kafka most admired) L'Éducation sentimentale. Poor Max Brod, the friend whom Kafka on his deathbed enjoined to burn his unpublished manuscripts, has been scoffed at for his determination to present Kafka as a religious writer, but the misapprehension is understandable. The Trial, The Castle and especially the stories, feel like religious parables – the chapter in The Trial called "In the Cathedral" might be a passage from one of the more obscure books of the Bible, or a gnomic exercise out of the Talmud.

And Brod is not alone in seeing his friend as, in at least some sense, a religious writer. Many later commentators and critics have accepted the religious dimension of these strange and strangely compelling works. Edwin and Willa Muir, Kafka's first English translators, presented him as a kind of tormented saint, and more recently George Steiner has identified The Trial as "an overwhelming feat of metaphysical-religious imagining and inquiry". The great scholar of German literature, Erich Heller, on the other hand, says of The Castle, as he might easily say also of The Trial, that it "is as much a religious allegory as a photographic likeness of the Devil could be said to be an allegory of Evil".

What Heller prizes in these fictions is their specificity, their groundedness in quotidian reality: "While it is in the nature of biblical parables to show meaning through concrete images to those who might be unable to comprehend meaning presented in the abstract, Kafka's parables seem to insinuate meaninglessness through nonetheless irrefutably real and therefore suggestively meaningful configurations." It is this aspect of The Trial that first strikes the reader. Although its atmosphere, at once lackadaisical and deeply sinister, is that of a nightmare, the book has the sheen of a wide-awake, hyper-real and terrifyingly definite experience.

The persuasiveness of Kafka's narratives is almost entirely an effect of his style, which native German-speakers will assure us is well-nigh unique in German literature for its simplicity, control and directness. The polished stuff through which these narratives are conveyed is as resistant and as transparent as glass, and the voice that speaks over it is at once thoroughly jaded and irresistibly compelling. Oneiric though it appears, this is the world not of Kafka's sleeping but of our waking, and the fascinated unease we experience in the face of it springs from the very fact of our recognition of it as impossible and yet wholly real.

Indeed, Kafka's work is a perfect illustration of Freud's conception of the uncanny as the familiar re-presented to us in unfamiliar guise. Strange as it all seems, we know this courtroom, these corridors, these airless overheated spaces; we recognise these people who peer down at us from cramped and crowded balconies, or through the crack of a partly opened door, or who take our hand and lead us with lascivious intent into this dim bedroom where a white blouse hangs on the latch of an open window through which two old people in the next building may be peering with inquisitiveness and a horrible knowing . . .

Kafka himself knew these places and occasions, knew them intimately and with what for him was appalling immediacy. On 13 August 1912, he attended a soirée at the home of Max Brod and his wife. One imagines the pre-war bourgeois scene: the heavy, dark furniture brooding in lamplight, the thickly curtained windows, the indistinct carpet, the doilies and the antimacassars, the head-achey air . . . In a diary entry two days later Kafka writes: "Thought much of – what embarrassment before writing down names – FB." In the context, one treasures the equally laconic note that Brod, the editor of the Diaries, attaches to this sentence: "Two days earlier Kafka had met Miss FB of Berlin, later to be his fiancée." Has a major figure in the life of a major writer ever stepped on to the scene with less seeming consequence?

"Miss FB of Berlin" was, of course, Felice Bauer, with whom Kafka was to carry on a tormented entanglement – it is the only word – for the next five years, proposing marriage, breaking off the engagement, proposing again, again backing out. Throughout those five years they met on no more than a handful of occasions, and for the rest communicated, if that is the word, by letter. Only Kafka's side of the correspondence survives, so that Felice's tremendous silence sounds in our ears as both enigmatic and, somehow, tragic. It was not until 20 August that Kafka describes the encounter to his diary. The entry merits quotation:

Miss FB. When I arrived at Brod's on 13 August, she was sitting at the table. I was not at all curious about who she was, but rather took her for granted at once. Bony, empty face that wore its emptiness openly. Bare throat. A blouse thrown on. Looked very domestic in her dress although, as it turned out, she by no means was. (I alienate myself from her a little by inspecting her so closely . . .) Almost broken nose. Blonde, somewhat straight, unattractive hair, strong chin. As I was taking my seat I looked at her closely for the first time, by the time I was seated I already had an unshakeable opinion.

Love at first sight, then, Kafka-style.

In the secretive, not to say furtive, life of the writer, his liaison with Bauer is one of the great mysteries. That she was some kind of muse for him there is no doubt: on the night of 22 September, exactly six weeks after that first meeting at the Brods', Kafka sat down before his desk in his room in the family home at 36 Niklasstrasse in Prague and wrote without interruption until dawn. The result was the darkly compelling story "The Judgment", in which the protagonist, Georg, obsessed with the figure of his father, as Kafka was, is at the end condemned by that father: "I sentence you to death by drowning." Kafka rightly judged it to be his first real literary breakthrough, and he dedicated it to Felice. Again the diary entry, made the next day, is striking:

This story, "The Judgment", I wrote at one sitting during the night of the 22nd–23rd, from ten o'clock at night to six o'clock in the morning. I was hardly able to pull my legs out from under the desk, they had got so stiff from sitting. The fearful strain and joy, how the story developed before me, as if I were advancing over water . . . How everything can be said, how for everything, for the strangest fancies, there waits a great fire in which they perish and rise up again.

Kafka's life was a continuing judgment against himself, and now he had someone who could be implicated along with him.

Writing to Felice in response to a declaration by her that they belonged together unconditionally, he takes up the notion with ghoulish enthusiasm, declaring he could have no greater wish "than that we should be bound together inseparably by the wrists of your left and my right hand. I don't quite know why this should occur to me; perhaps because a book on the French revolution, with contemporary accounts, is lying in front of me, and it may be possible after all . . . that a couple thus bound together were once led to the scaffold." Kafka certainly knew the way to a woman's heart.

In June of 1914 Kafka and Felice were engaged to be married. The Bauer family held a reception in Berlin to mark the happy event. On his return to Prague Kafka wrote in his diary: "Was tied hand and foot like a criminal. Had they sat me down in a corner bound in real chains, placed policemen in front of me, and let me look on simply like that, it could not have been worse." But he was wrong – worse was to come. In July, Felice's friend Grete Bloch, with whom Kafka was at least infatuated, warned Felice that her fiancé was getting cold feet. Kafka was summoned to the Askanische Hof hotel in Berlin, where he was confronted by Felice and her sister Erna, Bloch, and, as unconvinced defence lawyer, Kafka's friend Ernst Weiss, who had been against the engagement from the start. Throughout this "tribunal" (Gerichtshof), as he described it, Kafka spoke not a single word. The engagement was off. In his diary Kafka is studiedly cool, even nonchalant. "The next day didn't visit her parents again. Merely sent a messenger with a letter of farewell."

It was by no means the end of the affair, however. Back and forth went the letters, up and down went Kafka's regard for this woman who surely had the patience of a saint. There was another engagement, another break. There were unexpected moments of happiness, notably when, in July 1916, the two stayed together for 10 days at a hotel in Marienbad. Kafka wrote: "With F I knew intimacy only in letters, in a human way not until the last two days. The clarity is still lacking, doubts remain. But it is beautiful, the gaze of her calm eyes, the opening of womanly depth." As was to be expected, of course, he was happiest after she had left. At twilight, on the balcony where they had been together a few days previously, he writes by lamplight. He thinks of her, and sees himself as a biding force, as he beautifully intimates: "Someone must watch, it is said. Someone must be there." And then, a year later, on the night of 9–10 August, the solution to his dilemma arrives, in the form of a haemorrhage of the lungs. At last the judgment he had been awaiting all his life had been delivered. He was to live for another seven years, but his life with Felice was over. In 1919 she married another man, and later had two children and emigrated to America.

Elias Canetti, among others, has no doubt as to the origins of Kafka's great and terrible novel of guilt, judgment and retribution. "The trial . . . between him and Felice . . . changed into that other Trial . . ." This is dangerous territory, which one should enter with a delicate tread, circumspectly. It is deceptively easy to extrapolate directly from the writer's life to his work. Yet in this case the transfer seems plainly evident. Kafka began to write The Trial in August 1914, as the guns of Europe were being trundled up to the front line, and only weeks after the engagement-party debacle in Berlin and the subsequent tribunal at the Askanische Hof. One day Josef K is hauled before the courts on a charge that is never specified; the first hearing is held in an apartment next to his own, in the very bedroom, indeed, of his neighbour Fräulein Bürstner – Miss B – whose fleeting presence at the very end of the book conducts him on the first part of his forced march, wedged tight between the two gentlemen executioners, to the "small quarry, dreary and deserted", where the sentence upon him will be carried out, and where he will die "Like a dog!", as he declares with his last breath – the same dog, no doubt, that Kafka once compared himself to when, on a walk with Felice in the Tiergarten in Berlin, he humbled himself before her. Proust famously determined to transform a life into a book, and so too, it seems, did Kafka. And in bearing witness to his own torments he manages to implicate us all in his and K's fate. Just as the executioner's knife is about to be driven into the condemned man's heart, a mysterious figure appears at a window in the top storey of a house at the edge of the quarry: "The casement window flew open like a light flashing on; a human figure, faint and insubstantial at that distance and height, forced itself far out and stretched its arms out even further. Who was it? A friend? A good man? One who sympathised? One who wanted to help? Was it one person? Was it everybody?"

A new illustrated edition of The Trial will be published next month by the Folio Society.