While in the cave, Peri slips and falls into a strange sticky substance which makes her legs sting. The Doctor then helps her brush it off with his hands and tells her not to get caught in any more of the stuff. Moving deeper into the caves, they find piles of weaponry belonging to a gang of gun runners led by Stotz and his henchman, Krelper. As the Doctor and Peri begin to inspect the weapons, they are captured by Captain Roones who has them brought before General Chellak.
The General, holographically, communicates with Trau Morgus, the head of several conglomerate companies back on Androzani Major. Unknown to Chellak, Morgus, whose company is publicly funding the war against the gun runners, is also a patron of Stotz's gang. When Chellak informs him that Captain Roones had captured two gun runners he becomes concerned. However, when he sees the Doctor and Peri he changes his attitude and then orders that they be shot immediately. Chellak initaily protests on the grounds that he believes that they could be a source of useful information, but he gives in to Morgus' demands and orders the execution of the Doctor and Peri. Chellak has Major Salateen place the Doctor and Peri in detention and organize their execution.
Unknown to them, Chellak's conversation with Morgus has been monitored by a black-garbed and masked figure who notices Peri's beauty. He starts to assemble components in his laboratory and orders androids four and nine to join him. Meanwhile, Peri is restless in the detention. Her legs and the Doctor’s hands are coming out in blisters. The Doctor is suspicious of Salateen, and then he ponders as to why Morgus was so concerned that Chellack caught two gun runners, and then once he saw them, he lost all interest. As the Doctor laments on Morgus' "insult", someone enters their cell via a secret door.
Some of Chellak's men escort the confiscated weapons back to base, but Stotz and Krelper gun them down. The weapons are disposed of before Chellak can recapture them and the two leave before any reinforcements can arrive.
Morgus receives the President of Androzani Major in his office and gives him some spectrox. Spectrox, a drug that at least doubles the life span of humans, is the purpose for the Android Rebel War. However, the war is holding up spectrox supplies and the public demand for the drug is turning "ugly". The President is considering offering an armistice to Sharaz Jek, the man responsible for the war. For some unexplained reason, Morgus becomes horrified. On Androzani Minor, the Doctor and Peri are placed before a firing squad, and are executed.
Outside the cave, Stotz and Krelper argue. Krelper thinks they should cut their losses and leave, and the other gunrunners agree with him. Stotz manages to avert mutiny by promising his men they will be compensated for the lost shipment.
The Doctor complains about a cramp, like the one Peri had before. Salateen asked if they had stepped into any spectrox nests. When the Doctor describes a large sticky ball, Salateen laughs and tells the Doctor and Peri that they have contracted spectrox toxemia from touching raw spectrox. The Time Lord grabs Salateen and demands an explanation. Salateen stops laughing and explains that spectrox nests are deposits left from colonies of bats which live deep in the caves under Androzani Minor. He also says that cramps are the second stage of spextrox toxemia. Salateen initially tells them that there is no cure, but then admits that there is an anti-toxin, discovered by Professor Jackij - the milk from a queen bat. The problem is that all of the bats have gone to the deep caves, where there is no oxygen. Furthermore, to get to that level they must face the magma creature.
Jek is contacted by Stotz who demands payment in full for the lost consignment of weapons. He tells Stotz that he will meet him in person to discuss the dispute. As he begins to leaves his base, he overheard Peri ask the Doctor why does he wear a mask. Jek become irritated and explains that he wears a mask because he was hideously burned when Morgus trapped him in a mud-burst. He survived by getting to a baking chamber to escape the full force of the mud-burst. He was scalded near to death, but he lived to "one day avenge himself on that inhuman monster" Morgus.
Jek goes to meet Stotz to argue over the amount of payment for the recent shipment of lost weapons, ultimately agreeing to pay half price. In his absence, the Doctor is able to disarm the guarding android as it is programmed to recognize humans and his anatomy is different. As he makes his way to get the queen bat milk himself, the Doctor is wounded when he, Salateen and Peri are attacked by another android while moving through the caves. Salateen hurries Peri off to General Chellak, and the Doctor then has a close encounter with the magma beast as it attacks Stotz’s gun runners who foolishly attempt to find Jek’s private store of spectrox.
Stotz’s ship takes off, but the Doctor manages to free himself and pilot it back to Androzani Minor. As the Doctor takes control of ship, he begins to feel a sensation and his eyesight become temporarily blurred. The spectrox is damaging the Doctor's body and his body is warning him of the need to regenerate. The Doctor holds the regeneration back and fights it off so he can focus on saving Peri. As the Doctor approaches Androzani Minor, an irate Stotz, who is locked out of the control room, demands that the Doctor open the door. The Doctor simply ignores his demands and reminds Stotz to "find something firm to hang on to", as the Time Lord is "out of practice with manual landings". Stotz manages to cut his way into the control room and he points a weapon at the Doctor, demanding that he step away from the controls. The Time Lord says that Stotz's argument is not persuasive as he is already dying.
Meanwhile, Jek recaptures Peri who is by now very weak indeed. He raves about everything being Morgus's fault. Chellak and Salateen make their way towards Jek's base. However, the troops are ambushed by his androids. Salateen is killed along with some of the troopers, but Chellak pushes on. Eruptions on the surface herald the start of a mud-burst and Krelper returns to the spaceship to find Stotz and Morgus in conversation. Krelper is sent away and Morgus offers Stotz a share of the spectrox. He intends to take Jek’s private store of the drug and live on another planet in the Sirius system.
Jek’s androids are being overrun by Chellak's men. Jek goes to see if any of them can be repaired, but he too runs into the troops. Chellak chases Jek back to his lab where the two men struggle. Jek’s mask is pulled off and Chellak recoils in terror. The distraction allows Jek to push him outside into the path of a mud-burst, where he is killed.
Morgus calls his office and discovers to his surprise that his secretary, Trau Timmin, has taken control of his business. She has "deposed" him as the Chairman and Chief Director of Sirius Conglomerates and has given evidence against him. All of Morgus' power is gone and all his funds have been sequestered. Upon the news of Morgus' fall from greatness, Krelper and the other gun runner rebel. Krelper wants to return to Androzani Major with the spectrox they already have. Stotz guns him down, along with the remaining gunrunner. He and Morgus then go to the cave system to try to find Jek's spectrox store.
Jek is mourning Peri, who is almost unconscious when the Doctor arrives. The Doctor tells him that he is going to get the bat's milk and Jek gives him a half empty oxygen cylinder and directions to the lower levels of the caves. The Doctor negotiates the caves and crevasses — stumbling across the mysteriously dead body of the magma beast as he goes — until he reaches a dormant queen bat, and manages to fill a vial with enough milk to save himself and Peri.
Jek, trying to keep Peri's temperature down, activates a set of extractor fans, but Stotz and Morgus hear the sound and follow it to its source. Jek throws himself at Morgus and forces his head into the extractor fans, killing him and causing the fans to short circuit. Stotz shoots Jek but the android Salateen arrives and kills Stotz. As fire breaks out in the lab, Jek dies in the arms of the android Salateen. The Doctor returns with the milk in time to carry Peri out.
As the planet erupts around him, the Doctor manages to carry Peri back to the TARDIS. However, he accidentally spills the precious antidote while his blister filled hands were searching for the TARDIS key. The Doctor manages to save only half of the milk, meaning that only one of them could be cured. Without hesitation, he gives Peri the milk. She recovers quickly and sees the Doctor lying on the TARDIS's floor. The Doctor sees that Peri is well and says "Peri, well I see that Professor Jackij knew his stuff." Peri then asks the Doctor if he got the bat's milk and he confirms that he did. Peri then presses the Doctor into telling her where the antidote was. He simply tells her "Finished...Only enough for you." Peri looks on in horror and urges the Doctor not to give up and that there must be something they can do to save him. The Time Lord becomes doubtful and says "I might regenerate, I don't know... It feels different this time."
As the Doctor slowly rests his head, he enters a hallucinatory state. He first sees a small image of Tegan who says "What was that you always told me, Doctor? Brave heart?" Then an image of Turlough appears and says "You musn't die. Too many of your enemies would delight in your death." Then Kamelion appears and simply says "Turlough speaks the truth." Then an image of Nyssa of Traken appears and says "You're needed, you musn't die, Doctor." The final friendly image to appear was Adric who adds to Nyssa's statement by saying "You know that, you know that." The Doctor, who has long been haunted by the tragic loss of his Alzarian companion, cries out his name. However, the Doctor hears a cold and sinister laugh which drives all of the images of his companions away. It is the image of the Master. The Master begins to goad and taunt the Doctor, saying; "No my dear Doctor, you must die. Die, Doctor. Die, Doctor!" As the Master continues to laugh, his image becomes larger and the Doctor's face begins to glow. In a flash, the Doctor regenerates and awakens in the TARDIS to a new face and a shocked Peri. Peri attempts to ask the Doctor what happened. The Doctor turns towards the camera and says "Change, my dear, and it seems not a moment too soon..."