The Enterprise is escorting two robot grain ships filled with quintotriticale to Sherman's Planet to help with famine relief efforts. They spot a scout ship being fired upon by a Klingon battlecruiser and Kirk orders an intercept. Scotty locks onto the pilot with the transporter just as the Klingons destroy the scout ship. As Scotty attempts to rematerialize the pilot, the Klingons attack the Enterprise using a stasis beam that knocks out all higher energy functions on the ship, including the transporters. The Klingons are forced to use all their power to maintain the stasis field, rendering them unable to fire upon the Enterprise.
The Klingon captain, Koloth, contacts the Enterprise and demands they surrender the pilot for "ecological sabotage" against the Klingon Empire. Kirk refuses and Sulu reports that they're losing contact with the robot freighter ships. Kirk has Sulu take control of the ships and have them ram the Klingon battlecruiser. Koloth tries to divide the stasis field three ways and only succeeds in shutting it down from power overload. He opens fire on one freighter, disabling its warp engines, and flees.
With power restored to the systems, Scotty materializes the pilot on-board. Kirk and the others arrive to greet the pilot and discover that it's their old "friend," Cyrano Jones. Along with a transporter platform full of tribbles. Kirk orders the deck sealed but Cyrano explains that he genetically manipulated the tribbles and they no longer reproduce. When Kirk manages how Cyrano cleaned out the K-7 space station so quickly, Cyrano shows him a glommer: a tribble predator. He puts it next to a tribble and they watch as it neatly and fully eats the tribble in one bite. Cyrano has no idea why the Klingons want him for ecological sabotage, but admits that he unwittingly sold tribbles on a Klingon planet. After Spock checks Cyrano's record, Kirk has the space merchant put under arrest for various criminal charges against him.
McCoy confirms Cyrano's claim that the tribbles no longer get pregnant: they simply get larger. The command crew discusses the new Klingon weapon but Spock notes that the fact it immobilizes the ship employing it limits its tactical efficiency. The primary question is how long it will take the Klingon battlecruiser to recharge. Scotty informs them he's transferred all the grain from the damaged freighter to the Enterprise and it's filling up all the spare space.
The Enterprise continues to Sherman's Planet with the remaining freighter and the Klingon battlecruiser attacks again. This time it targets the remaining freighter immediately then fires on the Enterprise. The shock waves burst open the containers of grains, and the tribbles start eating the quintotriticale... and grow larger. The glommer, roaming the hallways, is having difficulty eating them. Kirk orders a tractor beam on the damaged freighter but Spock concludes that the Klingons want the Enterprise to direct more energy to the tractor beams, putting them at a tactical advantage. An irritable Kirk asks him what else they can do and Spock suggests throwing tribbles.
Scotty reports that the tribbles are growing as they eat the grain and Kirk calls Cyrano to the bridge. The Klingon battlecruiser attacks again and Kirk releases the tractor beam on the freighter. The Enterprise fires photon torpedoes but the Klingon fires its stasis beam, first nullifying the torpedo and then the ship. Koloth demands Cyrano's return but Kirk refuses. Koloth tells his men to implement Boarding Plan C. On the Enterprise, Kirk tells a puzzled Scotty to implement Emergency Defense Plan B.
Koloth's men go to the transporter room to board the Enterprise, but discover that the chamber is filled with tribbles. Very large tribbles. Kirk contacts Koloth, who hasn't yet been informed of the situation. When Koloth realizes what's going on, he reluctantly explains that Cyrano stole the glommer, a Klingon genetic prototype. They need it back so they can make more, and deal with the tribble infestation. Kirk is glad to agree once Koloth makes it clear they don't want Cyrano. Cyrano initially objects to losing the glommer, until Scotty offers to beam him over with his "pet." Cyrano hastily retracts his protest.
Upon receiving the glommer, Koloth releases the Enterprise. McCoy explains that Cyrano's genetic engineering was shipshod: he stopped them from giving birth to more tribbles externally, but they simply became colony creatures growing increasingly larger.
Koloth takes the glommer to his engineering room. However, when it sees the now super-large tribbles it runs away in terror. Koloth angrily tells his lieutenant to blast one of the tribbles, but it simply comes apart into hundreds of individual tribbles.
On the Enterprise, McCoy prepares an injection that will cause the colony tribbles to break apart and stop their breeding for good. Kirk notices one giant tribble in a Jefferies tube and says McCoy missed one, but McCoy says he got it. The tribble breaks apart and Kirk ends up buried under thousands of tribbles.