Strange things are happening in the Welsh village of Llanfer Ceirog. The police are investigating a coach crash which killed the driver and all passengers. Only the driver could be identified: Selwyn Hughes, brother of the coach's owner, Emrys Hughes, and resident of Llanfer Ceirog. Stuart Taylor, a veterinarian, tends to a horse with a strange wound in the middle of its forehead, and discovers a tapered horn nearby. When the Doctor and Ace arrive, they are greeted warmly until Ace is shot at by Emrys Hughes. The Doctor is intrigued to hear a legend of a village called Dinorben that vanished hundreds of years ago. Everything seems to be centered around the mysterious stone circle located on Emrys's land. The Doctor and Ace investigate the circle, only to find themselves transported to another world.
The city of Dinorben has become a desperate refuge of humanity. The head of the ruling council, Dryfid, explains that the sun mysteriously disappeared some time ago, and that they are beset by demons. The other people of the world, including unicorns, centaurs, trolls, and short, furry-footed creatures called the Sidhe, have become hostile after learning that the humans have a means of escaping their doomed world: the stone circle gateway to Earth. The Doctor and Ace are sent on a quest to find the living god Goibhnie and persuade him to restore his favor.
Back in Wales, two American hitchhikers stumble upon an injured centaur. Unable to believe what they've found, they seek help from the authorities. Unfortunately, they find the local Constable Hughes, who douses the centaur in gasoline and incinerates the corpse. The hitchhikers, Jack and David, manage to contact Inspector Stevens of Scotland Yard's Paranormal Investigations Division. Stevens is in the area investigating the mysterious coach, and trying to find the missing veterinarian who contacted him about the unicorn. Meanwhile, two figures resembling the Doctor and Ace return to Llanfer Ceirog, but they are really shape-shifting demons who kill and take the forms of two local residents.
The Doctor and Ace set off on their quest. They meet Bathsheba, a young girl with a withered arm, who tells them that her family was killed by demons while she was collecting firewood. They agree to take her with them, and she hopes that the god Goibhnie will see fit to restore her arm. After meeting Herne, a strange creature who apologizes to the Doctor for something that hasn't happened yet, they are captured by the Sidhe, evading execution when the Sidhe are attacked by an unseen force, allowing them to escape. They are next attacked by a demon, but rescued by Chulainn, a human returning to Dinorben for evacuation. Fearing for the safety of his companions, the Doctor asks Chulainn to take Ace and Bathsheba back to Dinorben with him. Bathsheba catches the Doctor trying to leave quietly, and insists on going with him.
Ace reluctantly agrees to return to Dinorben with Chulainn. She is contacted by Bat, a unicorn who can communicate with her telepathically. Chulainn is distrustful of all non-human creatures, so Ace abandons him and his party. She decides to return to Dinorben with Bat and the other unicorns, intending to force their way through the gateway and make themselves known to the Earth authorities, so that the other peoples of the dying world might also be saved. Meanwhile, the Doctor and Bat encounter a group of Firbolg (centaurs) along with veterinarian Stuart Taylor, who was sent on the same quest to reach Goibhnie. The Firbolg take them to Goihbnie's island, but they don't know how to contact the god. When the Firbolg slay a dragon, the Doctor discovers that it is in fact a bio-mechanical creature, technological rather than fantastical in origin.
Ace's assault on Dinorben is successful, and passing through the gateway, she finds the hitchhikers David and Jack along with Inspector Stevens, who were investigating Emrys Hughes's role in everything. When the soldiers of Dinorben overcome the shock of Ace's sudden attack, they regroup and follow her through the gateway, arrest Ace, David, Jack, and Stevens, and bring them all back to Dinorben. The soldiers have overcome the unicorns and forcefully removed their horns, destroying their psychic abilities. The Doctor gets an audience with Goibhnie, who turns out to be an alien scientist whose experiment has been completed. The Doctor appeals to Goibhnie's scientific curiosity to extend the experiment. Goibhnie restores the sun, and agrees to help collect the demons, which are discarded products of his experiments.
Ace discovers that General Nuada, the head of Dinorben's military, is in fact a shape-shifting demon. Nuada summons all of the demons for a final assault on Dinorben. David finds himself summoned by Nuada, since he was attacked by a demon when he came to Llanfer Ceirog as a child. Goibhnie returns to Dinorben, but is mortally wounded in the battle against the demons. David manages to hold onto his self-control and kills Nuada, and eventually with the Doctor's assistance, is restored to human form. Goibhnie gives the Doctor his power source, which the Doctor uses to reprogram the gateway. All of the demons are funneled into the stone circle, and transmatted to tne now rejuvenated sun.
The Doctor, Ace, Jack, David, Stevens, and Taylor return to Earth, and the stone circle is destroyed. The unicorns, now trapped on Earth, are beginning to recover. The Doctor promises Ace that UNIT will look after them. The Doctor uses Goibhnie's experimental material to repair his ailing TARDIS, unaware that a fleck of demonic material had contaminated the supply.
The duplicates of the Doctor and Ace reappear in Return of the Living Dad.