The Trouble With Tribbles - S2-E15
Trivia: According to the screenwriter David Gerrold, the producers of the show noticed a similarity of the plot line and story concept to Robert A. Heinlein's story "The Rolling Stones" and asked Heinlein for permission to use the idea. Heinlein asked for an autographed copy of the script, but otherwise did not object, noting that both stories owed something to the Ellis Parker Butler's 1905 short story "Pigs is Pigs" and perhaps "Noah". (Source "The Trouble With Tribbles: the birth, sale and final production of one episode" by David Gerrold).