Many years before the events in The Exorcist, the young Father Lankester Merrin (played by Skarsgård, who played the same part in Exorcist: The Beginning) travels to East Africa. Merrin has taken a sabbatical from the Church and devoted himself to history and archaeology as he struggles with his shattered faith. He is haunted especially by an incident in a small village in occupied Holland during World War II, where he served as parish priest. Near the end of the war, a sadistic Nazi SS commander, in retaliation for the murder of a German trooper, forces Merrin to participate in arbitrary executions in order to save a full village from slaughter.
In 1947, Merrin is an archaeologist in the Turkana region of British Kenya excavating a Christian Byzantine church built around the 5th century — long before Christianity had reached that region of Africa. He meets up with Father Francis, a Maryknoll missionary appointed to ensure the church not be desecrated, and Major Granville, the British military officer overseeing the dig.
In the village, Merrin meets Rachel, a doctor who spent time in a concentration camp during World War II and is haunted by what happened to her there. Merrin’s translator and guide is Chuma. Merrin takes Francis on a tour of the dig site. Only the dome is uncovered; the rest of the church is yet buried beneath the earth. Merrin discovers to his surprise the church is in perfect condition, as though it had been deliberately buried immediately after its construction was completed. Merrin hires more men to uncover the church’s walls; as excavation continues, one of the diggers inexplicably experiences a seizure, which was however dismissed as simple heat-stroke.
On the site, Merrin meets a shy, physically-deformed young boy named Cheche, shunned and mistreated by the local tribespeople for fear he is cursed. Although dissuaded by Chuma, Merrin attempts to make contact with Cheche, eventually finding him again at the village, sleeping outside in the rain. He brings the boy to the infirmary, where Rachel looks after him. That night, Merrin has a disturbing dream featuring several nightmarish images (one of which is the face of Satan).
Once the door is uncovered, Merrin, Francis, and Chuma go inside the church, finding it to be also in near-pristine condition. Francis however points out an oddity: churches were built to honour God and thus, usually reached up to the heavens, whereas this building seems as if it is restraining something below it.
They find a passageway leading to an underground crypt beneath the church, where they find demonic icons and signs of human sacrifice. Merrin deduces the church was built and then buried in order to hold this older pagan temple down. On their way back, they find hyenas (who have appeared out of season) were somehow killed and then eaten by a herd of cattle. The chiefs of the local tribesmen, fearing the church is evil, demand Merrin stop the excavation.
Father Francis then contacts Major Granville to send a detachment to guard the dig from potential robbers, despite Merrin’s objections. Two British soldiers attempting to loot some precious stones from the church are then found murdered the next day in a strange fashion (one was beheaded, like John the Baptist; the other crucified to the altar head downward, in the style of Saint Peter). Granville blames the tribesmen for the attempted robbery and the murders. Meanwhile Cheche, who had just received an operation on his right leg, is healing at an unusually quick pace.
Granville then appears at the village in a rage, demanding the local chiefs give up the purported murderers, even shooting one of the tribeswomen in cold blood. Francis is wracked with guilt for summoning the British troops to the village. Things get worse when a tribesman, Jomo, assaults Francis and slaughters the children attending the village school under the pretext of stopping the ‘Christian evil’ from spreading but is caught in the act and shot.
Francis and Rachel note Cheche’s speedy recovery & think it must be a miraculous sign. As Francis prays over the boy, however, he quickly realises (to his discomfort) it was not a sign form God, but something sinister. He then considers the idea of baptising Cheche; the boy accepts on the condition it be held at the church. Meanwhile, Granville – visibly disturbed by his own actions at the village – commits suicide by shooting himself in the mouth. The Sergeant Major reports what had happened to Merrin, remarking at the same time how Granville’s actions at the village last time were strangely out-of-character.
As the locals prepare to wage war against the British troops, Francis, assisted by Rachel, attempts to baptise Cheche at the church but is prevented by the demon controlling Cheche from doing so. Realising an exorcism is in order, Francis leaves quickly to fetch his copy of the Roman Ritual. The demon gains full control of the boy, transforming him into a hairless, androgynous being; an earthquake erupts and seals off the entrance to the church, trapping Rachel and Cheche inside. Merrin asks for the doors to be cleared, but the Sergeant Major (who had assumed command of the troops after Granville’s death) postpones his request for daybreak.
The next morning Merrin and the British find Francis tied to a tree naked, shot with arrows (a clear parallel to the martyrdom of Saint Sebastian). Taken back to the village infirmary, the dying Francis reveals to Merrin that Cheche is possessed and begs him, to perform an exorcism.
As Merrin makes his way back at the excavation site, another earthquake shifts the rocks blocking the doors, allowing him to go inside. At the crypt, Merrin finds Rachel – who runs away under a trance – and the now-possessed Cheche. When the demon confronts Merrin over his doubt and offers him a chance to clear himself of his guilt, Merrin dashes back to the infirmary to get Francis’ vestments and the Roman Ritual. He prays that God will help his unbelief.
Returning to the crypt, Merrin, now garbed as a priest, begins the exorcism, as the demon once more promises him a chance to change his past. In a hallucination, Merrin finds himself reliving the incident at Holland: despite attempting to change what happened by refusing to cooperate with the Germans, his efforts are proved to be in vain as the troops kill Merrin and all the villagers in retaliation for his defiance.
Back to the present, the demon mocks Merrin for his futile attempt. As Merrin attempts to proceed with the exorcism, an aurora appears in the sky as the entranced Rachel attempts to kill herself and the tribesmen charge to battle. Despite the evil spirit’s attempts to thwart Merrin, the latter eventually succeeds in driving him out, ending the madness; Cheche regresses to his former condition as the demon leaves his body.
At the end of the movie, the British troops are packing up to leave the village, whilst the locals finally live in peace.
As Merrin himself prepares to depart, one of the local chiefs wishes him strength, while warning that the demon is now his enemy and will continue to pursue him. Merrin then makes his way to the infirmary (briefly stopping by Francis’ grave along the way) to bid farewell to Rachel and Cheche, now serving as Rachel’s assistant. After receiving a rosary from Rachel as a parting gift, Merrin, now an active priest once more, leaves for Rome.