The Doctor is making adjustments to the TARDIS's coordinate programmer in preparation for a visit to the blue planet of Metebelis Three, when Jo reads in the paper about the mysterious death of a miner named Hughes in the abandoned coal mine in Llanfairfach in South Wales: The miner, doing a monthly inspection of the bottom of the mine shaft, emerged dead and glowing bright green. Jo takes this opportunity to meet the acclaimed local environmentalist and Nobel Prize winner Professor Clifford Jones; while Brigadier Lethbridge-Stewart goes down to investigate the miner's death, taking Jo with him in his car. The Doctor agrees to follow the Brigadier, but is determined to go to Metebelis Three first.
The Brigadier's first port of call is the recently opened Global Chemicals oil plant, close to the abandoned mine. Its headman, Stevens, claims that the plant can "produce 25% more petrol and diesel fuel from a given quantity of crude oil" - but that the 'Stevens process' only produces a minimal amount of waste. Jones, in his environmentally friendly retreat the 'Wholeweal', (nicknamed the "Nuthutch" by the locals), is convinced that the oil-making process must create thousands of gallons of waste. He also believes that there is a link between Global Chemicals and Hughes's death - but his research is too demanding for him to go down the mine and investigate. Jo, who is on the environmentalist's side, heads for the mineshaft.
The Doctor reaches Metebelis Three, but it is far from the "blue paradise" he described: He is attacked by various unseen creatures, returning to the UNIT laboratory with only a small blue crystal to show for his misadventure. He then drives down to South Wales in his car, Bessie, and meets the Brigadier at Global Chemicals. The two then set off to go down the mine to investigate, despite Stevens's insistence that the mine should be sealed. Stevens summons his henchman, Hinks, and tells him in a strange emotionless voice "nobody must go down the mine". Hinks leaves, and Stevens dons a pair of strange headphones.
Jo has arrived at the pithead ahead of the Doctor and the Brigadier, and gone down the shaft with a miner called Bert to help another man, Dai Evans, who has called for help at the bottom of the mine. When the Doctor and the Brigadier arrive, Dave, the man controlling the cage's descent, finds that the brake has been sabotaged. The Doctor manages to slow the cage's descent, but his efforts leave Jo and Bert trapped at the bottom of the shaft. There, they find Dai Evans, who is turning bright green and dying. Bert remembers there is an emergency shaft out of the mine, and he and Jo set off.
The Doctor suggests cutting the mineshaft cables linking the two cages together, which would enable him to use the second cage to get down the mine. The Brigadier goes to Global Chemicals to request some cutting equipment, but a man named Fell informs him that they do not have such equipment. The Doctor has Professor Jones and his Wholeweal friends create a demonstration at the Global Chemicals gate, while he slips in an attempt to steal the equipment from where it is stored in a large shed. However, he is captured, and Stevens shows him that the shed is empty. Fortunately, Dave and the Brigadier, while on their way to Newport to find some cutting equipment, have stopped at a petrol station and found a man using the required equipment to cut up an old car. They borrow this, free the secondary mine cage, and the Doctor goes down the shaft with Dave and two other miners. They finds Dai Evans now dead, and a note from Jo telling them that she and Bert have headed for the emergency shaft.
Jo and Bert have made good progress through the old mine tunnels, when they find a green slime trickling down the wall. When Bert touches this, he begins to grow weak, and his hand starts to turn bright green. At Bert's insistence, Jo goes on without him. Dave and the Doctor find Bert, and the Doctor goes on to find Jo. By the time they reunite, Jo has found a vast lake of bright green slime, filled with huge maggot creatures. When the tunnel collapses behind them, they use an old mining wagon to get across the green lake. They then climb a steep shaft, where the Doctor collects a huge egg to take back for experimentation. At the top of the natural shaft, they find a large pipe, with the insides covered with traces of crude oil waste - meaning that the pipe leads to the Global Chemicals plant.
In the plant, a worker named Elgin, an old friend of Fell, tells him about Dai Evans's death and the dying Bert. Elgin later follows Fell into a pumping control room, where Fell is pumping the oil waste from the main tank on level four into another tank. The security system then registers the Doctor and Jo's presence in the pipe. Fell, who has actually arranged for the waste to be pumped down the pipe into the abandoned mine workings, is initially reluctant to rescue the two in the pipe. Elgin convinces Fell to help him open the hatch, and the Doctor and Jo escape as the oil waste cascades down the pipe. Fell goes to see Stevens, complaining about a 'headache', and Stevens puts the strange headphones on Fell. A voice tells Stevens that 'Fell's 'processing' was a failure' and orders self-destruction. After Stevens presses a button on a small control panel, Fell leaves the room and jumps off a balcony to his death.
The Doctor, Jo and the Brigadier end the day with a meal of fungus at the Nuthutch, but the frivolity is cut short when they hear Bert too has died. After everyone retires to bed, while Jo stays up to read a book about the Amazon - where Jones is planning to go on an expedition in search of a rare toadstool - the egg the Doctor brought back from the mine hatches out into a giant maggot. Escaping from the lab where the egg was left, the maggot first heads for Jo, but then jumps on and bites Hinks, sent to the Nuthutch by Stevens to steal the egg. The maggot escapes from the house into the dark, and Hinks quickly weakens as the poisonous "green death" infection spreads through his body. The next morning, the Brigadier has the UNIT troops lay explosives and detonate the whole mine pithead, to the Doctor's fury. This fails to trap the maggots in the mine, as they begin to emerge; first, attempting to escape up the Global Chemicals waste disposal pipe, then burrowing through the slagheap near the mine.
At Global Chemicals, Mike Yates has been sent in undercover by the Brigadier, and is contacted by the Doctor, who dons some improbable disguises to get through the gates and move freely. Having liased with Yates, the Doctor learns that Stevens take his instructions from someone on the top floor of the complex, and heads up there in the special lift to find out who is in charge. He finds that this is the home of the BOSS, Bimorphic Organisational Systems Supervisor, a supercomputer with its own megalomaniac personality. It runs the company, controls Stevens and other key staff members, and is responsible for the polluting chemical process. The Doctor rejects the brainwashing technique that Stevens and the BOSS subject him to – but Yates is more susceptible and is converted into one of the computer’s slaves. After the Doctor escapes, Yates is sent to the Nuthutch to kill the Doctor. His conditioning is deep and only broken by the Doctor’s use of the blue crystal he brought from Metebelis Three.
Jo has alienated Jones, with whom she is falling in love, by ruining one of his experimenting slides of green slime. Determined to make amends, she heads to the slagheap in search of a maggot to run some tests on. Meanwhile, Jones finds that the fungus powder Jo spilt on the slides is actually a cure for the 'green death' infection. He races to the slag heap to find Jo surrounded by giant maggots, and they are both caught in an RAF bombing raid on the maggots. Jones is infected with the 'green death' and begins to turn green — and all before he was able to share his knowledge of the cure. Jo contacts her UNIT friends with her radio, and the Doctor and Sergeant Benton rescue the two from the maggots in Bessie. Hearing Jones utter the word "Serendipity", the Doctor realises that Jones might have stumbled upon something that could combat the maggots and their infection. Benton arrives with a maggot crysallis - proof that the maggots are beginning to transform into mature giant insects. Then, the maggot that escaped from the laboratory is found on the table - dead. Realising that the creature died from eating some of the fungus, the Doctor also discovers the cure for Jones. The Doctor and Benton drive around the slag heaps, liberally scattering the fungus, which proves deadly to the maggots. They are then attacked by a giant fly creature - the mature adult form of the maggots - which the Doctor kills by throwing his cloak over it when it is in mid-air, causing it to fall to the ground.
The Doctor returns to Global Chemicals to confront the BOSS. The computer plans to link up with others and effect a corporate takeover of the human race. By now, Stevens is completely under the mad computer's control. The Doctor tells Stevens that the BOSS's "efficiency" will result in greater pollution, brainless brainwashed humans, and more death and disease. The Doctor then uses his blue crystal to break Stevens's hypnotic state, and Stevens, infuriated at what the BOSS has done to him, cross-feeds the generator circuits, causing the whole plant to explode, apparently destroying Stevens and the mad computer.
The menace defeated, UNIT troops and environmentalists gather at the Nuthutch for a celebration made all the more special when Jo and Jones announce they are getting married. The Doctor gives his blessing and gives Jo the blue crystal as a wedding present, but since this means the end of Jo's travels with the Doctor, he is evidently upset by the situation and quietly slips away while the party is in full swing.