Contrary to popular belief, Andrei Tarkovsky did not know he was dying of cancer when he made The Sacrifice (1986). Indeed, he had already started contemplating future projects, which included a biography of the German writer E.T.A. Hoffmann (provisionally entitled Hoffmanniana) and an adaptation of William Shakespeare's Hamlet. Tarkovsky's interest in the latter is particularly intriguing, as there are several points of reference between the story of a Danish prince who prevaricates over avenging his father's murder and a Swedish father who decides that 'words, words, words' are not enough and strikes a bargain with God to prevent the world war that is likely to claim the life of his son. This most tantalising connection is a fortuitous one, as while the lines, 'To die, to sleep. To sleep, perchance to dream,' from the famous 'To be or not to be' soliloquy, may not be spoken, they prove key to understanding The Sacrifice, a film whose ambiguity has resulted in many divergent readings.

While promoting the film, Tarkovsky claimed 'I wanted to show that one can resume life by restoring the union with oneself and by discovering a spiritual source. And to acquire this kind of moral autonomy, where one ceases to consider solely the material values, where one escapes from being the subject article of experimentation between the hands of society - a way - among others - is having the capacity to offer oneself in sacrifice.'

The story told in The Sacrifice is significantly different to the one Tarkovsky had originally planned to relate in a screenplay titled The Witch. 'The Sacrifice is a parable,' he once revealed. 'The significant events it contains can be interpreted in more than one way. The first version was entitled The Witch and it told the story of the hero's amazing cure from cancer. His family doctor having told him that his days were numbered, Alexander answered the door one day and was confronted by a soothsayer - the forerunner of Otto in the final version - who gave Alexander a strange, almost absurd instruction: he was to make his way to a woman reputed to be a witch and spend the night with her. The sick man obeyed as his only way out and, through God's mercy, was cured; this was confirmed by the astonished doctor. And then one wretched, stormy night, the witch appeared at Alexander's house, and at her bidding he happily left his splendid mansion and respected life and went off with her with nothing but the old coat on his back.'

However, when Anatoly Solonitsyn - who had taken the title role in Andrei Rublev (1966) and had also featured prominently in Solaris (1972), Mirror (1975) and Stalker (1979) - succumbed to cancer in 1982, Tarkovsky was too devastated to pursue his original intention and redrafted the scenario to focus on a potential holocaust. But the irony was not lost on him, as he confided to his diary that the disease had finally caught up with him, as 'today, years later, I too am suffering from it'. While this may have turned out to be an accidental allusion to Tarkovsky's off-screen life, there is still plenty of autobiographical detail in the script. By then exiled from the Soviet Union, Tarkovsky had been worried about the fate of his young son Andrei and was grateful to actor Maximilian Schell for sending 10,000 roubles to the family in Moscow to help them pay their debts. Cruelly, Tarkovsky would only be able to see Andrei again after he had been diagnosed with cancer in December 1985 and it is touching to note that he dedicated the film to the boy 'with hope and confidence'.

One wonders whether Tarkovsky ever uttered anything similar to the prayer that Alexander offers up in a rare moment of privacy in The Sacrifice that almost sounds like an extract from a Shakespearean monologue: 'Lord, deliver us in this terrible hour. Do not let my children die, my friends, my wife... I will give you all I possess. I will leave the family I love. I shall destroy my home, give up my son. I shall be silent, will never speak with anyone again. I shall give up everything that binds me to life, if You will only let everything be as it was before, as it was this morning, as it was yesterday: so that I may be spared this deadly, suffocating, bestial state of fear.'

Alexander (Erland Josephson) is a philosopher with a belief in the rational rather than the spiritual, which allows him to be convinced of the prevalence of sin - 'Sin is that which is superfluous; and that being the case, our whole civilisation consists from beginning to end of sin.' - without being persuaded by the existence of a deity. Yet, he prays for himself and his loved ones to be spared Armageddon. It could be argued that, unlike Hamlet, he decides to act. Or he could have been so tormented by memories of the past wars he had witnessed that it was his subconscious that appealed to God for clemency. Alexander certainly falls asleep during the course of his birthday night (indeed, there is a possibility that his fear of ageing and the creeping inevitability of his own demise shape his imaginings rather than the threat of conflagration). But which parts of that momentous evening occur in waking reality and which in his sleeping mind?

Who is to say that Alexander hasn't dozed off before he takes a nap after praying? He kneels almost as soon as he hears the news bulletin about the imminence of conflict and appears to drop off soon afterwards. As he slumbers, he seems to see his stepdaughter Marta (Filippa Franzén) offering herself to Victor (Sven Wollter), the doctor lover of her mother Adelaide (Susan Fleetwood), while Alexander himself heads off into the snow to find his missing son, Gossen, who is known to everyone as Little Man (Tommy Kjellqvist). Yet, when Alexander wakes to Otto the postman (Allan Edwall) arriving during what seems to be a power cut to suggest that he could avert the imminent global disaster by sleeping with Maria (Guðrún S. Gísladóttir) Alexander seems not to know what he is talking about. The house has just been shaken to its core by jets flying overhead, yet Alexander seems blithely unaware of the crisis he is being urged to prevent. He could simply be sleepy and disorientated after his strange visions or he could be cocooned in a dreamworld that he had entered on finding the model house that Little Man has made for his birthday. Acting according to dream logic would certainly explain the alacrity with which Alexander falls in with Otto's far-fetched proposal and his willingness to continue on his fool's errand to Maria's house even after falling off the postman's borrowed bicycle as he rides through the darkened countryside.

Adding to the sense of ethereality is the cry of the unseen shepherd that pierces the night. But events take an even more surreal (ie dreamlike) turn once Alexander crosses Maria's threshold. As they make love, the couple levitate above the bed and the scene shifts to show the mute Little Man sleeping contentedly as the townsfolk rush through the streets in understandable panic. The next image shows Maria dressed in Adelaide's clothing, as she looks down indulgently on her lover snoozing on a camp bed, while the reverie ends with a bizarre shot of the naked Marta chasing chickens along a corridor.

This sequence begs the question, therefore, whose dream are we actually watching - Alexander's or Little Man's? The boy was certainly asleep in his room before dinner, as Adelaide sends Julia the maid (Valérie Mairesse) to wake him and he refuses to come and pretends to still be asleep when his father enters his room. Moreover, by lying beneath the tree as Alexander is taken away in an ambulance in the closing scene, it could be that Little Man is trying to dream himself another solution to an intractable problem.

There is, of course, a third option, as Maria appearing to catch sight of the charred ruins of a smouldering building suggests that we are witnessing a prophetic vision of what will befall Alexander and his family the following morning. Such ambiguity is typical of Tarkovsky and he even uses our knowledge of his earlier films to mislead us. In Nostalgia (1983), Erland Josephson had played Domenico, another holy fool who had set fire to himself in Rome while chanting a prayer for forgiveness. As Tarkovsky had used monochrome for the illusory segments in that film, it is easy to assume that he has followed the same scheme here as a saint rather than a madman sacrifices himself for others.

But Tarkovsky and cinematographer Sven Nykvist employ a tripartite strategy, as they also use desaturated colours shot in the Scandinavian 'white night' that form an uncertain middle ground between what is presumed to be the black and white of the fantasy sequences and the full colour of reality. The scene in which the family watch the TV news is clearly in colour. But we don't see the same bright hues until the following morning when the crisis has passed. Yet, even though this would seem to imply that everything between these scenes has taken place in the imagination of one or possibly more of the characters, some critics have even reached the conclusion that the denouement alone is dreamed, while others insist that everything happens as we see it and that there are no fantastical elements at all.

Does Alexander really believe that a random action by a single individual can stop a thermonuclear war? Or is the conflict simply the blinding light that causes him to experience a Damascene conversion? Could he and Maria actually have persuaded God that their desperate resort to extramarital coitus was sufficiently sanctified to prevent a catastrophe? Does Alexander sacrifice his sanity to save the planet or does he merely feign madness (as, indeed, does Hamlet) in order to keep his end of the bargain while retaining an outward appearance of atheism?

We shall never know for sure. But this remarkable film does seem to confirm Tarkovsky's deep spiritual conviction and the truth of Hamlet's contention that 'there are more things in heaven and earth, Horatio, than are dreamt of in your philosophy'.