With the arrival of summer holidays the students of Kiev seminary leave the school to go home or find summer jobs in the country. The students travel in a large group, but eventually, only three boys remain; Khalava, the theologist, Thomas Brutus, the philosopher, and Tiberius Gorobetz, the rhetorician.
One day, the three boys are looking for a village where they could safely stay the night, however, instead they get lost. Finally, they come across a farm with couple of houses. In one of the houses, an old woman opens the door, but she refuses to accommodate them. After some persuasion she allows them to stay.
During the night, the old woman visits Thomas. Initially, he thinks she is trying to seduce him, however, when she comes closer, Thomas notices a strange gleam in her eyes. Afterwards, the old woman leaps on his shoulders and makes him run throughout the fields. As he is ridden by the witch, Thomas starts to recite some exorcism, which weakens her, and their roles reverse. Now, it is Thomas riding the witch. Finally, he finds a piece of wood and beats up the old woman as a punishment. When she collapses, Thomas notices, she turned into a pretty, young girl.
Following the incident, Thomas returns to Kiev, where he resumes his regular life. After some time, word gets to the seminar, that a daughter of a rich colonel returned home nearly dead, and that her last wish is for Thomas Brutus, the philosopher, to come and recite psalms for three nights after her death. Thomas is reluctant towards undertaking this task, but the rector of the seminar orders him to go.
When Thomas arrives the the colonel’s estate, accompanied by several Cossacks, he recognizes the witch in the corpse of the dead girl. The servants also tell him stories about the young lady’s involvement with the devil.
At night, the cossacks drag Thomas into a church, where the coffin with the dead girl is laying. He is frightened, nevertheless, he starts to recite the psalms. He constantly imagines the corpse rising from the coffin, but when he looks, it is always in the same position. However, once when Thomas takes a quick glance at the coffin, he finds the dead girl sitting up. Afterwards, she gets up and follows Thomas, but he manages to draw a circle around himself, that she cannot cross.
The second night, similar events take place, but they are much worse. This time it is not just the dead girl trying to capture Thomas, but also numerous other monsters. However, none of the monsters can see Thomas, therefore they are unable to get to him. The next morning, the Cossacks find Thomas half-dead from fright. He tries to escape, but is unsuccessful.
The third night, everything is even more terrifying. The witch calls upon the monsters to bring in Viy, the King of Gnomes, who sees everything. Thomas knows, it is not a good idea to look at him, nevertheless, when the monsters lift up Viy’s long eyelids, he does, and he sees a horrible iron face. Viy points towards Thomas and all the monsters leap upon him. Thomas dies of fear. Soon after, the monsters try to make their escape, but before they are able to flee the church, the rooster crows and they freeze in the windows. Thomas’s friends discuss the the circumstance of his death, and they come into conclusion that he only ended up the way he did because he showed his fright.